banner



Creat-react-app Use Material-design-icons

  • Updated date Jan 17, 2020
  • 46.3k
  • 7

In this article, you will learn how to use material UI icons in ReactJS application.

Introduction

In this article we will learn how to use Material-UI Icons in a React application.React Material UI provide more than 1000 icons. Material UI is one of the most popular UI frameworks developed by Google.The Material UI library is designed for faster, easier and developer-friendly user interface development. Now Material-UI supported by all major browsers and platforms.

You can check my previous articles in which we discussed the basics of Material UI, from the below mentioned links

  1. npx create-react-app matform

Open the newly-created project in Visual Studio Code and install Material-UI and Material-UI icons by using following commands.

Install Material-UI

  1. npm install @material-ui/core --save

Install Material-UI icons

  1. npm install @material-ui/icons

Now, right click on "src" folder and add a new component named 'MatIcon.js'. import following icons in this component.

  1. import Home from '@material-ui/icons/Home' ;
  2. import  Notifications  from'@material-ui/icons' ;
  3. import ContactsIcon from'@material-ui/icons/Contacts' ;

 Add the following code in this component.

  1. import React, { Component } from 'react'
  2. import Home from'@material-ui/icons/Home' ;
  3. import AppBar from'@material-ui/core/AppBar' ;
  4. import Toolbar from'@material-ui/core/Toolbar' ;
  5. import { Notifications } from'@material-ui/icons' ;
  6. import ContactsIcon from'@material-ui/icons/Contacts' ;
  7. exportclass  MatIcon extends Component {
  8.         render() {
  9. return  (
  10.                         <div>
  11.                                 <AppBar className="mrg"  position= "static" >
  12.                                         <Toolbar>
  13.                                         <Home/>   <Notifications/>  <ContactsIcon/>
  14.                                         <div style={{'paddingLeft' : "600px"  }}>   Material UI Icons</div>
  15.                           </Toolbar>
  16.                                 </AppBar>
  17.                                 <Home/> Home Icon <br></br>
  18.                                 <Notifications/> Notification Icon<br></br>
  19.                                 <ContactsIcon/> Contact
  20.                         </div>
  21.                 )
  22.         }
  23. }
  24. exportdefault  MatIcon

Now add reference of this component in app.js file and run by using 'npm start' command,

How To Use Material UI Icons In ReactJS Application

Now add one more component, named 'MatIcon1.js', ,in this component we add social media icons. Add the following code in this component

  1. import React, { Component } from 'react'
  2. import FacebookIcon from'@material-ui/icons/Facebook' ;
  3. import AppBar from'@material-ui/core/AppBar' ;
  4. import Toolbar from'@material-ui/core/Toolbar' ;
  5. import TwitterIcon from'@material-ui/icons/Twitter' ;
  6. import LinkedInIcon from'@material-ui/icons/LinkedIn' ;
  7. import MailIcon from'@material-ui/icons/Mail' ;
  8. import InstagramIcon from'@material-ui/icons/Instagram' ;
  9. import YouTubeIcon from'@material-ui/icons/YouTube' ;
  10. exportclass  Maticon1 extends Component {
  11.         render() {
  12. return  (
  13.                         <div>
  14.                                 <AppBar className="mrg"  position= "static" >
  15.                                         <Toolbar>
  16.                                                 <div style={{'paddingLeft' : "600px"  }}>   Material UI Social media Icons</div>
  17.                                         </Toolbar>
  18.                                 </AppBar>
  19.                                 <FacebookIcon/><br></br>
  20.                                 <TwitterIcon/> <br></br>
  21.                                 <LinkedInIcon/><br></br>
  22.                                 <MailIcon/><br></br>
  23.                                 <InstagramIcon/><br></br>
  24.                                 <YouTubeIcon/><br></br>
  25.                         </div>
  26.                 )
  27.         }
  28. }
  29. exportdefault  Maticon1

Now add reference of this component in app.js file and run by using 'npm start' command,

How To Use Material UI Icons In ReactJS Application

We also add css to the icons to change styles.

  1. import React, { Component } from 'react'
  2. import FacebookIcon from'@material-ui/icons/Facebook' ;
  3. import AppBar from'@material-ui/core/AppBar' ;
  4. import Toolbar from'@material-ui/core/Toolbar' ;
  5. import YouTubeIcon from'@material-ui/icons/YouTube' ;
  6. exportclass  Maticon1 extends Component {
  7.         render() {
  8. return  (
  9.                         <div>
  10.                                 <AppBar className="mrg"  position= "static" >
  11.                                         <Toolbar>
  12.                                                 <div style={{'paddingLeft' : "600px"  }}>   Material UI Social media Icons</div>
  13.                                         </Toolbar>
  14.                                 </AppBar>
  15.                                 <FacebookIcon style={{'color' : "Blue"  }}/><br></br>
  16.                                 <YouTubeIcon style={{'color' : "red"  }}/><br></br>
  17.                         </div>
  18.                 )
  19.         }
  20. }
  21. exportdefault  Maticon1

Now add reference of these components in app.js file,

  1. import React from 'react' ;
  2. import logo from'./logo.svg' ;
  3. import'./App.css' ;
  4. import Maticon1 from'./Maticon1'
  5. function App() {
  6. return  (
  7.     <div className="App" >
  8.       <Maticon1/>
  9.     </div>
  10.   );
  11. }
  12. exportdefault  App;

Now run the project and check result.

How To Use Material UI Icons In ReactJS Application

Summary

In this article, we learned how to use the Material-UI Icons in a React application. React Material UI provides more then 1000 icons. Material UI is one of the most popular UI frameworks developed by Google. The Material UI library is designed for faster, easier and developer friendly user interface development.

Creat-react-app Use Material-design-icons

Source: https://www.c-sharpcorner.com/article/how-to-use-material-ui-icons-in-reactjs-application/

Posted by: morrismenced.blogspot.com

0 Response to "Creat-react-app Use Material-design-icons"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel