Z
Z
zwezew2019-03-21 21:20:11
React
zwezew, 2019-03-21 21:20:11

React adding components to an array?

How to adequately implement the entry of components into an array in order to call it from there by component id? Where exactly is it better to specify the id for the component?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mytz, 2019-03-22
@mytz

If you need to get it by IDs, then you can do it without arrays:

const myComps = {
  firstComponent: YouComponentHere,
  another: YourAnotherComponent,
  "compo1232_34232": Comp1,
  "f": ({ text }) => <div>Hello, { text }</div>,
  "ну вы поняли": TestComponent,
}

// Достаем
const Component = myCompos.another;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question