Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Material UI icons in React?

Tags:

reactjs

I'm new to react and am working on an existing React component. I need to include an icon and noticed that some were already being brought in, like:

import KeyboardArrowLeftIcon from 'material-ui/svg-icons/action/keyboard-arrow-left';

I couldn't locate the folder (material-ui/svg-icons/action/), but tried to add a new icon:

import KeyboardArrowRightIcon from 'material-ui/svg-icons/action/keyboard-arrow-right';

However, this generates an error on compiling.

Would anyone know how I could add a new icon? Or, why there is no apparent director for these icons?

like image 215
MeltingDog Avatar asked Jun 13 '18 05:06

MeltingDog


People also ask

Can we use material UI in React?

Get started with React and Material UI in no time. Material UI components work in isolation. They are self-supporting, and will only inject the styles they need to display.


1 Answers

  1. install material icon: npm install @material-ui/core @material-ui/icons

  2. import the icon you will use: import MenuIcon from '@material-ui/icons/Menu';

  3. use the icon: <MenuIcon/>

You can also use https://material-ui.com/components/material-icons/ to search for the icon you need.

like image 69
M Danil Rafiqi Avatar answered Sep 20 '22 14:09

M Danil Rafiqi