[Docs & Types] Importing icons from @material-ui/icons in TypeScript
See original GitHub issueImporting icons with the way mentioned in tutorial will raise type errors.
import { Icons } from 'material-table';
const tableIcons: Icons = {
Add: AddBox,
Check: Check,
Clear: Clear,
Delete: DeleteOutline,
DetailPanel: ChevronRight,
Edit: Edit,
Export: SaveAlt,
Filter: FilterList,
FirstPage: FirstPage,
LastPage: LastPage,
NextPage: ChevronRight,
PreviousPage: ChevronLeft,
ResetSearch: Clear,
Search: Search,
SortArrow: ArrowUpward,
ThirdStateCheck: Remove,
ViewColumn: ViewColumn
};
// Type 'ComponentType<SvgIconProps>' is not assignable to type '(() => ReactElement<any, string ...
The correct way should be
const tableIcons: Icons = {
Add: () => <AddBox />,
Check: () => <Check />,
Clear: () => <Clear />,
Delete: () => <DeleteOutline />,
DetailPanel: () => <ChevronRight />,
Edit: () => <Edit />,
Export: () => <SaveAlt />,
Filter: () => <FilterList />,
FirstPage: () => <FirstPage />,
LastPage: () => <LastPage />,
NextPage: () => <ChevronRight />,
PreviousPage: () => <ChevronLeft />,
ResetSearch: () => <Clear />,
Search: () => <Search />,
SortArrow: () => <ArrowUpward />,
ThirdStateCheck: () => <Remove />,
ViewColumn: () => <ViewColumn />
};
It seems that the type of icons are declared as Add?: () => React.ReactElement<any>;
, which forces imports to be arrow functions, but the icons are exported from @material-ui/icons as React.ComponentType<SvgIconProps>
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Material-UI: How to declare a type for React.ComponentType ...
However, it is not possible to retrieve type information about the ... Reference: [Docs & Types] Importing icons from @material-ui/icons in ...
Read more >React Icon Component - Material UI - MUI
Icons. Guidance and suggestions for using icons with MUI. MUI provides icons support in three ways: Standardized Material Icons exported as React components ......
Read more >@material-ui/icons - npm
This package provides the Google Material icons packaged as a set of React components. Installation. Install the package in your project ...
Read more >Material Icons Guide | Google Fonts
Material design system icons are simple, modern, friendly, and sometimes quirky. Each icon is created using our design guidelines to depict in simple...
Read more >How to Use Material UI Icons In React - Flatlogic Blog
How to import a React Material UI icon for your project · Step 1. Installing Material UI framework. · Step 2. Installing Material...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@robinlarsson Me too
Closing due to updated docs.