ok guys I have a problem.
I need render a list which has a title and a icon . and I Want to render it dynamic with map method.
This is the backend api object(Its more than 2 :D )
// icons are Material UI Icon component
const list = [
{title: 'Vehicle', icon: 'DirectionsCarFilledOutlined'},
{title: 'Electronic', icon: 'PhoneIphoneOutlined'},
]
What I have to do is to render this icon COMPONENT dynamic
something like this
import {
DirectionsCarFilledOutlined,
PhoneIphoneOutlined,
} from "@mui/icons-material";
const list = [
{title: 'Vehicle', icon: 'DirectionsCarFilledOutlined'},
{title: 'Electronic', icon: 'PhoneIphoneOutlined'},
]
{list.map(({ title, icon }) => {
return (
<div>
<p>{title}</p>
<div>{<icon />}</div> // Problem is here. IDK How to render it
</div>
);
})}
I Wrote switch case for this problem but that's bad and if we add new items to api those lists won't have icon.
Is there anyway to render this Icons dynamic ?
<phoneiphoneoutlined></phoneiphoneoutlined>