Easiest Way To Add Icons To Your React Apps ?

A great UI begins with some great icons.

Icons are important as they add familiarity to your website. Such as a hamburger menu. Everyone knows to click a hamburger icon to get more information, or how a down arrow at the bottom of the page, …


This content originally appeared on DEV Community and was authored by Chris Hansen

A great UI begins with some great icons.

Icons are important as they add familiarity to your website. Such as a hamburger menu. Everyone knows to click a hamburger icon to get more information, or how a down arrow at the bottom of the page, indicates the user should scroll.

If you're working with React, it's extremely easy to implement icons into your projects, with thousands of choices from various libraries.

Let's begin.

Resources

1. We're going to be using the react-icons package ?

Download react-icons either with yarn or npm. Like so:

yarn add react-icons 
or 
npm install react-icons --save 

2. Import Icons ↩️

On the react-icons homepage, you'll see a ton of libraries to choose from. From Bootstrap, Font-awesome, Material-UI and many more. Choose your favorite.

Once you find the icon you like, click to add the code to your clipboard.

Now, in App.js all we need to do is import the Icon and the library like so:

// fa is the reference to the font-awesome library
import { FaReact, FaSass, FaLinux} from 'react-icons/fa';

// md is the reference to the material-ui library
import { MdFavoriteBorder, MdChat } from 'react-icons/md';

3. Let's use our icons ?

Lastly, in your App() component, all you need to do is use the Icon like any other component. So back in step 2, if you imported the React, Sass, Linux, Favorites and Chat Icons, just use them like so:

function App() {
  return (
    <ul>
      <li><FaReact/></li>
      <li><FaSass/></li>
      <li><FaLinux/></li>

      <li><MdFavoriteBorder/></li>
      <li><MdChat/></li>
    </ul>
 );
}

Conclusion ?

Congrats! That's it! That's all it takes to bring Icons into your React projects. You have the choice of thousands of Icons from 21 different libraries! And the best part is you only import the Icons you need from each individual library, which helps with performance!

So bring some flare to your UI, & get creative!

Are you on the Web Dev learning journey!?

Check out my other posts on productivity and React.

.ltag__tag__id__6357 .follow-action-button{ background-color: #57d700 !important; color: #ffffff !important; border-color: #57d700 !important; }

#codenewbies Follow


.ltag__tag__id__2162 .follow-action-button{ background-color: !important; color: !important; border-color: !important; }

#tutorials Follow


This content originally appeared on DEV Community and was authored by Chris Hansen


Print Share Comment Cite Upload Translate Updates
APA

Chris Hansen | Sciencx (2021-08-10T00:01:58+00:00) Easiest Way To Add Icons To Your React Apps ?. Retrieved from https://www.scien.cx/2021/08/10/easiest-way-to-add-icons-to-your-react-apps-%f0%9f%98%8e/

MLA
" » Easiest Way To Add Icons To Your React Apps ?." Chris Hansen | Sciencx - Tuesday August 10, 2021, https://www.scien.cx/2021/08/10/easiest-way-to-add-icons-to-your-react-apps-%f0%9f%98%8e/
HARVARD
Chris Hansen | Sciencx Tuesday August 10, 2021 » Easiest Way To Add Icons To Your React Apps ?., viewed ,<https://www.scien.cx/2021/08/10/easiest-way-to-add-icons-to-your-react-apps-%f0%9f%98%8e/>
VANCOUVER
Chris Hansen | Sciencx - » Easiest Way To Add Icons To Your React Apps ?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/10/easiest-way-to-add-icons-to-your-react-apps-%f0%9f%98%8e/
CHICAGO
" » Easiest Way To Add Icons To Your React Apps ?." Chris Hansen | Sciencx - Accessed . https://www.scien.cx/2021/08/10/easiest-way-to-add-icons-to-your-react-apps-%f0%9f%98%8e/
IEEE
" » Easiest Way To Add Icons To Your React Apps ?." Chris Hansen | Sciencx [Online]. Available: https://www.scien.cx/2021/08/10/easiest-way-to-add-icons-to-your-react-apps-%f0%9f%98%8e/. [Accessed: ]
rf:citation
» Easiest Way To Add Icons To Your React Apps ? | Chris Hansen | Sciencx | https://www.scien.cx/2021/08/10/easiest-way-to-add-icons-to-your-react-apps-%f0%9f%98%8e/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.