ListItemIcon with Typescript
See original GitHub issueI am using the latest version of the material-ui theme with typescript but I get the below error when trying to define a ListItemIcon. Any ideas what am I doing wrong? the issue seems to be down to the icon type as the children property resolves to shouldUpdate() instead of a ReactElement…
import {
**Dashboard**
} from 'material-ui-icons';
export type AppRoute = {
redirect?: boolean,
to: string,
from?: LocationDescriptor,
path: string,
**icon?: React.ComponentType<SvgIconProps>,**
sidebarName?: string,
navbarName: string,
component?: React.ComponentType
};
const appRoutes: Array<AppRoute> = [
{
path: '/dashboard',
sidebarName: 'Dashboard',
navbarName: 'Material Dashboard',
to: '',
**icon: Dashboard,**
component: DashboardPage
},
{redirect: true, path: '/', to: '/dashboard', navbarName: 'Redirect'}
];
<ListItem button={true} className={classes.itemLink}>
<ListItemIcon className={classes.itemIcon + whiteFontClasses + listItemClasses}>
{prop.icon}
</ListItemIcon>
<ListItemText
primary={prop.sidebarName}
className={classes.itemText + whiteFontClasses}
disableTypography={true}
/>
</ListItem>
index.js:2177 Warning: Failed prop type: Invalid prop
children
of typefunction
supplied toListItemIcon
, expected a single ReactElement. in ListItemIcon (created by WithStyles(ListItemIcon)) in WithStyles(ListItemIcon) (created by Sidebar) in div (created by ButtonBase) in ButtonBase (created by WithStyles(ButtonBase)) in WithStyles(ButtonBase) (created by ListItem) in ListItem (created by WithStyles(ListItem)) in WithStyles(ListItem) (created by Sidebar) in a (created by Link) in Link (created by Route) in Route (created by NavLink) in NavLink (created by Sidebar) in ul (created by List) in List (created by WithStyles(List)) in WithStyles(List) (created by Sidebar) in div (created by Sidebar) in div (created by Paper) in Paper (created by WithStyles(Paper)) in WithStyles(Paper) (created by Drawer) in div (created by Drawer) in Drawer (created by WithStyles(Drawer)) in WithStyles(Drawer) (created by Sidebar) in HiddenJs (created by WithWidth(HiddenJs)) in EventListener (created by WithWidth(HiddenJs)) in WithWidth(HiddenJs) (created by WithTheme(WithWidth(HiddenJs))) in WithTheme(WithWidth(HiddenJs)) (created by Hidden) in Hidden (created by Sidebar) in div (created by Sidebar) in Sidebar (created by WithStyles(Sidebar)) in WithStyles(Sidebar) (created by App) in div (created by App) in App (created by WithStyles(App)) in WithStyles(App) (created by Route) in Route in Switch in Router
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (3 by maintainers)
Top GitHub Comments
I encountered a similar issue, and was able to use the SvgIconProps from the SvgIcon export:
I had the same issue. The problem is that you must set the icon as an element with the starting and closing tags. So
icon: <DashboardIcon/>
(react element) instead of justicon: Dashboard
(react component).