Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cound not find icon react-fontawesome

I have a project on React and I need to integrate FontAwesome to it. I found official library and installed it as instructed in readme

$ npm i --save @fortawesome/fontawesome $ npm i --save @fortawesome/react-fontawesome 

When I try to use it in my code like this:

<FontAwesomeIcon icon='plus'/> <FontAwesomeIcon icon={['fa', 'coffee']}/> 

I am getting this error on the console:

Could not find icon {prefix: "fas", iconName: "plus"} Could not find icon {prefix: "fa", iconName: "coffee"} 

I tried to include FontAwesome css link to head but it didn't help. I am using npm v4.6.1; node v8.9.1; react v16.2.

like image 761
iamawebgeek Avatar asked Dec 28 '17 06:12

iamawebgeek


People also ask

Why can't I See my icon in react-fontawesome?

I've installed all the necessary packages as react-fontawesome says: And if you find yourself not seeing your icon when trying to display faTrashAlt (or similarly named icon), not only do you have to remove the 'fa' when actually using your icon but also you have to convert the icon name from cameCase to "lisp-case".

How do I use Font Awesome with react?

, you can put this code in src/__mocks__/@fortawesome/react-fontawesome.js to automatically include it in any tests, and alleviate errors. Our hope and intention is that React users will use this package ( react-fontawesome) when using Font Awesome. This component leverages React's architecture and philosophy.

How do I add icons to my react app?

There are a few ways to add icons when using React. The easiest way is to use Dynamic Icon Importing which automatically imports the icons you're using - and only the icons you're using. But you can choose other methods that allow you to explicitly add individual icons or add icons to a global library.

Why should I use React-fontawesome?

Our hope and intention is that React users will use this package ( react-fontawesome) when using Font Awesome. This component leverages React's architecture and philosophy. If you cannot use these components everywhere in your app and still have <i> tags on your page that need to be converted to <svg> tags we can still help you.


1 Answers

You need to add any icons you wish to use, to a "library" for easy reference.

import React from 'react'; import { render } from 'react-dom'; import Hello from './Hello'; import fontawesome from '@fortawesome/fontawesome' import FontAwesomeIcon from '@fortawesome/react-fontawesome'; import { faCheckSquare, faCoffee } from '@fortawesome/fontawesome-free-solid'  const styles = {   fontFamily: 'sans-serif',   textAlign: 'center', };  fontawesome.library.add(faCheckSquare, faCoffee);  const App = () => (   <div style={styles}>     <FontAwesomeIcon icon="check-square" /><br /><br />     <FontAwesomeIcon icon="coffee" />   </div> );  render(<App />, document.getElementById('root')); 

Check out working code here: https://codesandbox.io/s/8y251kv448

Also, read this: https://www.npmjs.com/package/@fortawesome/react-fontawesome#build-a-library-to-reference-icons-throughout-your-app-more-conveniently

like image 184
Shishir Avatar answered Sep 20 '22 21:09

Shishir