E
E
Eugene2019-03-06 23:30:11
React
Eugene, 2019-03-06 23:30:11

How to map a key value to an element?

How to save a key in the store with a value pointing to a specific react component?
There are a number of ready-made components, you need to render a specific component depending on the value set.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Robur, 2019-03-07
@dbrr

It will be correct not to save the component key in the store, but to save the data from which you can understand which component to render. If it is one of the list of some values, for example - id or index of the list element.
If it is difficult to think in this way - the easiest way is to give each component its own unique id and save it in the store. Type

{store.activeComponent === "component1" && <Component1/>}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question