The Font Awesome documentation shows only how to add regular/solid fonts to React. How about social icons?
First I grabbed the packages:
npm i --save @fortawesome/fontawesome-svg-core \ npm i --save @fortawesome/free-brands-svg-icons \ npm i --save @fortawesome/react-fontawesome
Note: I replaced npm i --save @fortawesome/free-solid-svg-icons \
with npm i --save @fortawesome/free-brands-svg-icons \
Then in React:
import { library } from '@fortawesome/fontawesome-svg-core' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faFacebookF } from '@fortawesome/free-brands-svg-icons' library.add(faFacebookF);
And tried using a component:
<FontAwesomeIcon icon="fa-facebook-f" />
even tried:
and keep getting in the console
Could not find icon {prefix: "fas", iconName: "fa-facebook-f"}
I believe I somehow have to get the fab
prefix for brands.
This is the icon I want to use https://fontawesome.com/icons/facebook-f?style=brands
css file in your css file. Then You also need to copy the fonts of font-awesome file and paste it into your fonts folder. In this code it will show a address book icon. Go to font-awesome website to know others icon code.
Try:
<FontAwesomeIcon icon={['fab', 'facebook-f']} />
Note that font awesome now has different icon sets. The solid set (fas
) is the default. The facebook icon is in the brands set (fab
).
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { faFacebook } from "@fortawesome/free-brands-svg-icons" const icon = <FontAwesomeIcon icon={faFacebook} />
I found the spelling/casing of the brand icons on FontAwesome's GitHub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With