avatarMalcolm

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

3415

Abstract

efits:</p><ul><li>Accessibility. They are treated like images instead of text, so you can use attributes like <code>title</code> and <code>description</code> for users with screen readers.</li><li>Easily customizable with CSS, and can even be animated.</li><li>Inline SVGs are included in the HTML document, so they require no further HTTP requests and don’t suffer from the flash of invisible text like font based icons.</li></ul><p id="69a8">So without further ado, let’s take a look at the best SVG icon sets to use for a React application 2020.</p><h2 id="1303">1. React Icons</h2><figure id="f11b"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*QDekT2-_ZUEtGFUZoQ7d8Q.png"><figcaption>React Icons</figcaption></figure><div id="949c" class="link-block"> <a href="https://github.com/react-icons/react-icons"> <div> <div> <h2>react-icons/react-icons</h2> <div><h3>Include popular icons in your React projects easily with react-icons, which utilizes ES6 imports that allows you to…</h3></div> <div><p>github.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*lsUBhuDVDe63VkJG)"></div> </div> </div> </a> </div><p id="97a6">React Icons offers popular sets of icons, including <b>FontAwesome</b>, Ant <b>Design</b>, <b>Material Design</b> and more. They can be imported one by one using ES6 syntax.</p><div id="270c"><pre><span class="hljs-keyword">import</span> { FaHeart } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-icons/fa'</span>;</pre></div><div id="95cf"><pre><span class="hljs-keyword">const</span> <span class="hljs-title function_">Home</span> = (<span class="hljs-params"></span>) => ( <span class="language-xml"><span class="hljs-tag"><<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/"</span>></span><span class="hljs-tag"><<span class="hljs-name">FaHeart</span> /></span><span class="hljs-tag"></<span class="hljs-name">a</span>></span></span> );</pre></div><p id="8b29">You can even use the <a href="https://reactjs.org/docs/context.html">React Context API</a> to configure global configurations for your react-icons.</p><div id="2a4d"><pre><span class="language-xml"><span class="hljs-tag"><<span class="hljs-name">IconContext.Provider</span> <span class="hljs-attr">value</span>=</span></span><span class="hljs-template-variable">{{ <span class="hljs-name">className:</span> <span class="hljs-string">"my-icon-classname"</span> }}</span><span class="language-xml"><span class="hljs-tag">></span> <span class="hljs-tag"><<span class="hljs-name">App</span> /></span> <span class="hljs-tag"></<span class="hljs-name">IconContext.Provider</span>></span>;</span></pre></div><h2 id="0b0c">2. Styled Icons 💅</h2><figure id="7952"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*miuf7k46qE0yr70zTIjESQ.png"><figcaption>Styled Icons</figcaption></figure><div id="c2c1" class="link-block"> <a href="https://github.com/jacobwgillespie/styled-icons"> <div> <div> <h2>jacobwgillespie/styled-icons</h2> <div><h3>styled-icons provides over 13,500 icons from

Options

the following icon packs as Styled Components, with full support for…</h3></div> <div><p>github.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*xW7jkXI72z4KPk6j)"></div> </div> </div> </a> </div><p id="27b8">Styled-Icons offers over 13,500 icons from popular icon packs as styled-components. It also offers TypeScript support and ES6 style imports. If your project is already using <a href="https://styled-components.com/">styled-components</a>, then styled-icons is a great choice.</p><div id="4330"><pre><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span> <span class="hljs-keyword">import</span> { <span class="hljs-keyword">Lock</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'@styled-icons/material'</span></pre></div><div id="71f0"><pre>const Lock <span class="hljs-operator">=</span> () <span class="hljs-operator">=</span>> <Lock size<span class="hljs-operator">=</span><span class="hljs-string">"48"</span> title<span class="hljs-operator">=</span><span class="hljs-string">"Unlock account"</span> /></pre></div><h2 id="fd74">3. React Feather</h2><figure id="eede"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*2uR1D07iTeFDqtyroOL4Fw.png"><figcaption>Feather Icons</figcaption></figure><div id="2947" class="link-block"> <a href="https://github.com/feathericons/react-feather"> <div> <div> <h2>feathericons/react-feather</h2> <div><h3>What is react-feather? react-feather is a collection of simply beautiful open source icons for React.js. Each icon is…</h3></div> <div><p>github.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/)"></div> </div> </div> </a> </div><p id="6bbb">As you might have guessed from the name, react-feather offers the <a href="https://feathericons.com/">feather icons</a> as a set of React components. Feather bill itself as “simply beautiful open source icons”, and they aren’t kidding. What they lack in numbers, they more than makeup for in quality.</p><div id="20d1"><pre><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>; <span class="hljs-keyword">import</span> { Camera } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-feather'</span>;</pre></div><div id="48bc"><pre>const App = <span class="hljs-function"><span class="hljs-params">()</span> =></span> { <span class="hljs-keyword">return</span> <Camera /> };</pre></div><div id="17cf"><pre><span class="hljs-built_in">export</span><span class="hljs-built_in"> default </span>App;</pre></div><p id="db26">Feather icons are a great choice to make your app stand out, as many applications use popular icon sets like Material Design and Font Awesome.</p><p id="eda4">These are my favourite icon libraries to use when I start a new React application. What about you? Let us know what your favourite library is, and how you incorporate icons into your web applications.</p></article></body>

The Three Best React Icon Libraries

And why you should use icons in your next application

Photo by Ryoji Iwata on Unsplash

Take a look at the websites and applications you use most frequently. You might notice they have something in common. That’s right, they all make use of icons. Like the proverb, “a picture is worth a thousand words”. As web developers, we can use icons to spice up our websites and grab our users’ attention.

Take a look at Instagram. They use icons for their navigation. A heart for your likes, a compass to discover, and a house to return home. These icons are used instead of text and require global recognition to be useful.

A look at the icons used in the Instagram application

Icons can be especially useful for navigation on websites that are translated into many different languages. For example, if we had a design that relied on our “home” navigation text being relatively short (four characters), how will it look in French, where we use the word “acceuil” (seven characters) instead?

However, we should use icons to replace text when they have one clear, recognizable meaning. Like bathroom. When I’m visiting a new country, I might not know the word for the bathroom, but I can sure recognize the symbol.

Photo by Juan Marin on Unsplash

So now that we have established the widespread use, and usefulness of icons in web design, let’s take look at how we can easily incorporate into our next React application.

Let’s start with our acceptance criteria. We want a library that

  • Can be imported one by one (without unused icons)
  • The icons should be SVG-based, not font-based.
  • Works out of the box without changes to our build setup.

Why SVG?

In the past, uses font based icons was all the rage. You might remember using font awesome in previous projects. However, using font-based icons has the following drawbacks:

  • Font sets contain icons that you (probably) won’t use, so they bloat your bundle size.
  • They require performing another HTTP request to fetch the font set.
  • They lead to invisible text flashing (when the font loads), leading to a poor user experience.
  • They have bad accessibility, as we can’t provide meaning to users with screen readers
  • They are hard to position, and you need to play around with line-height to get them vertically centred.

Whereas, using SVG based icons gives us the following benefits:

  • Accessibility. They are treated like images instead of text, so you can use attributes like title and description for users with screen readers.
  • Easily customizable with CSS, and can even be animated.
  • Inline SVGs are included in the HTML document, so they require no further HTTP requests and don’t suffer from the flash of invisible text like font based icons.

So without further ado, let’s take a look at the best SVG icon sets to use for a React application 2020.

1. React Icons

React Icons

React Icons offers popular sets of icons, including FontAwesome, Ant Design, Material Design and more. They can be imported one by one using ES6 syntax.

import { FaHeart } from 'react-icons/fa';
const Home = () => (
  <a href="/"><FaHeart /></a>
);

You can even use the React Context API to configure global configurations for your react-icons.

<IconContext.Provider value={{ className: "my-icon-classname" }}>
  <App />
</IconContext.Provider>;

2. Styled Icons 💅

Styled Icons

Styled-Icons offers over 13,500 icons from popular icon packs as styled-components. It also offers TypeScript support and ES6 style imports. If your project is already using styled-components, then styled-icons is a great choice.

import React from 'react'
import { Lock } from '@styled-icons/material'
const Lock = () => <Lock size="48" title="Unlock account" />

3. React Feather

Feather Icons

As you might have guessed from the name, react-feather offers the feather icons as a set of React components. Feather bill itself as “simply beautiful open source icons”, and they aren’t kidding. What they lack in numbers, they more than makeup for in quality.

import React from 'react';
import { Camera } from 'react-feather';
const App = () => {
  return <Camera />
};
export default App;

Feather icons are a great choice to make your app stand out, as many applications use popular icon sets like Material Design and Font Awesome.

These are my favourite icon libraries to use when I start a new React application. What about you? Let us know what your favourite library is, and how you incorporate icons into your web applications.

JavaScript
Design
Programming
Front End Development
React
Recommended from ReadMedium