I face this problem when I try to put react-fontawesome in gatsby[v2] projects, but I don't know how to do it. There's no document or anything about how to do it at all
Thanks
gatsby-config.js
: N/A
package.json
: N/A
gatsby-node.js
: N/A
gatsby-browser.js
: N/A
gatsby-ssr.js
: N/A
The documentation of this font awesome package explains it quite well — you import the icon and then use it. You need to be more specific with your error.
There's no App.js or Index.js in gatsby to put the import statement
You would import that in your Layout
component that wraps all pages.
It's not working even if I put import and library.add(xxx,xxx) in Layout component
@KamiGim We'll need some more information to be able to help - could you create an example repo on GitHub and post a link here?
@KamiGim
here is how I am making use of fontawesome with v2 in my site. Works with no issues.
@rockchalkwushock Thanks a lot I will try it
@rockchalkwushock Link is not working. Can you please check.
This was super easy.Try this if you are looking for font-awesome icons.
https://www.npmjs.com/package/react-icons
@KamiGim, you can make react-fontawesome work by adding the following code snippet (mentioned in official react-fontawesome docs) in your layout component as told by @LekoArts.
import { library } from '@fortawesome/fontawesome-svg-core'
import { fab } from '@fortawesome/free-brands-svg-icons'
import { faCheckSquare, faCoffee } from '@fortawesome/free-solid-svg-icons'
library.add(fab, faCheckSquare, faCoffee)
first
npm install -S
andimport
free-brands-svg-icons or/ and free-solid-svg-icons only if you need icons from them.
Then in each component where to use icons, add the following code:
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
Now use it in your component like shown below:
<FontAwesomeIcon icon={["fab", "apple"]} style={{color:"#000000"}} />
I believe it is at this step where things go wrong. You need to include 'fab' in
icon
prop as shown above if you are adding brand icons. Otherwise if using (let say) solid icons, then just enter the spinal-case (e.g check-square) styled name of the icon without [] enclosing brackets inicon
prop instead of camelCase (checkSquare) and you don't need to include 'fa' in the beginning.
I hope this helps you and others experiencing same issue.
@LekoArts can we follow similar flow to make it work on your gatsby-cara-theme starter
Most helpful comment
@KamiGim, you can make react-fontawesome work by adding the following code snippet (mentioned in official react-fontawesome docs) in your layout component as told by @LekoArts.
Then in each component where to use icons, add the following code:
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
Now use it in your component like shown below:
<FontAwesomeIcon icon={["fab", "apple"]} style={{color:"#000000"}} />
I hope this helps you and others experiencing same issue.