question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Docs & Types] Importing icons from @material-ui/icons in TypeScript

See original GitHub issue

Importing 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:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
argentinaluizcommented, Jun 16, 2019
0reactions
Domino987commented, Jun 4, 2020

Closing due to updated docs.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found