Answer the question
In order to leave comments, you need to log in
How to create dynamic component name in React?
Hello everyone
Actually, I want to dynamically create components with icons.
Here's how it looks:
importing an icon from above:
import {Dashboard as MdDashboard} from "react-icons/lib/md/dashboard"
const content = sidebar ? (
sidebar.map((element, index) => {
return (
<li key={index}>
<div className="icon">
//тут вывод
</div>
<a href="#">{element}</a>
</li>
);
})
) : (
<div>Loading, please, waits</div>
);
<div className="icon">
<{element} />
</div>
<div className="icon">
{React.createElement(
element,
{size: 14}
)}
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question