Hello. I’m trying to create Sidebar component and inside of it render SidebarOptions which are distinct buttons of a sidebar. The problem appears when I’m trying to pass Material UI icons (HomeIcon, SearchIcon etc) as props to my child component. The error says: ‘Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object’. So how can I fix it and pass icon as prop?
//Sidebar component
import React from 'react';
import HomeIcon from '@material-ui/icons/Home';
import Sidebaroptions from './sidebaroptions';
import SearchIcon from '@material-ui/icons/Search';
import NotificationsIcon from '@material-ui/icons/Notifications';
export default function Sidebar() {
const vals = [['Home', <HomeIcon />],['Explore', <SearchIcon />], ['Notifications', <NotificationsIcon />]]
return (
<div className='sidebar'>
{
vals.map(e => {
return (
<Sidebaroptions text={e[0]} icon ={e[1]} />
)
})
}
</div>
)
};
//SidebarOptions component
import React from 'react';
import './sidebaroptions.css'
export default function Sidebaroptions({text, Icon}) {
return (
<div className='sidebar-option'>
<Icon />
<h2>{text}</h2>
</div>
)
}