The current code is as follows
const financeFlags = [
{
name: "Billing",
icon: <CompanyPinIcon />,
},
{
name: "Supply",
icon: <CommanderPinIcon />,
}
]
Now i import the financeFlags to the component
import { financeFlags } from ...
Now i want to loop through the array, get the icon component and add new props to it.
I have modified the code as
{financeFlags.map((flag) => (
<IconComponent flag={flag} classes={classes} />
))}
const IconComponent = ({ flag, classes }) => {
const Component = flag.icon;
return (
<Component
className={classNames(classes.icon, {
[classes.unflagged]: true,
})}
/>
);
};
Currently, i am getting the error
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
If flag.icon
is set as CompanyPinIcon
instead of <CompanyPinIcon />
then there is no error. But i need to pass it in the array as <CompanyPinIcon />
since it is used in several places.
Any idea on how to fix this?