Could someone advice me on how to integrate FontAwesome 5 Pro with React?
I know there are packages @fortawesome/react-fontawesome and for example @fortawesome/fontawesome-free-regular but is there a way how to include pro version of icons?
When I log in to FontAwesome website, I can download the pro-version JS but I guess that's of no use in React.
Here's how to integrate Font Awesome 5 Pro with React (2018):
npm config set ...
or locally per project via (B) .npmrc
. I recommend (B) so other team-mates can also install the pro package.For (B), Go to your package.json directory and create a .npmrc
file. In that file, paste the code snippet provided in the guide. It should look something like this:
// .npmrc
@fortawesome:registry=https://npm.fontawesome.com/
//npm.fontawesome.com/:_authToken=<MY_AUTH_TOKEN_FROM_FONT_AWESOME>
Once done, you should now be able to install the pro packages. They are according to the official react adapter react-fontawesome available as the following npm packages:
npm install @fortawesome/pro-<MY_ICON_WEIGHT>-svg-icons
to install the pro package of your choice.Thereafter, continue usage as provided by the react-fontawesome package. Which should look something like this in your react code if you installed the light version and using the 'Library' method by react-fontawesome:
// app.js
import { library, config } from '@fortawesome/fontawesome-svg-core'
import { fal } from '@fortawesome/pro-light-svg-icons'
library.add(fal)
Finally, usage looks something like this in a component file (available in both JS and TS flavours):
// Foo.jsx
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
const Foo = () => {
return (
<FontAwesomeIcon icon={['fal', 'utensils']} />
)
}
export default Foo
And if you are into Typescript:
// Foo.tsx
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { IconLookup } from '@fortawesome/fontawesome-svg-core'
const Foo = () => {
const icon: IconLookup = { prefix: 'fal', iconName: 'utensils' }
return (
<FontAwesomeIcon icon={icon} />
)
}
export default Foo