Answer the question
In order to leave comments, you need to log in
How to do dynamic rendering?
There is a component that dynamically renders components by type. Now it happens like this: one under the other. What is the right thing to do in this case, if I need the Title component (all elements) in section.
To get something like this:
<main>
<section>
<Title />
<Title />
<Title />
</section>
<New />
</main>
const Factory = ({ widget }) => {
const widgetType = widget.type.toLowerCase()
const Component = components[widgetType]
if (widgetType === 'title') {
// я так понимаю, вот здесь должна быть логика
}
return (
<Component widget={widget} />
)
}
Answer the question
In order to leave comments, you need to log in
What is the right way to do this...
The data structure cannot be changed.
If I understand you correctly, then this is how you can do it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question