Font Awesome 5 use social/brand icons in React

China☆狼群 提交于 2019-12-05 19:15:26

问题


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


回答1:


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).




回答2:


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




回答3:


Note that you must run the commands that you ran first:

npm i --save @fortawesome/fontawesome-svg-core 
npm i --save @fortawesome/free-brands-svg-icons 
npm i --save @fortawesome/react-fontawesome

I'd tried to import without installing first - and of course that didn't work.



来源:https://stackoverflow.com/questions/52687229/font-awesome-5-use-social-brand-icons-in-react

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!