Font Awesome 5 use social/brand icons in React

后端 未结 5 1540
南笙
南笙 2021-02-18 17:59

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 @         


        
相关标签:
5条回答
  • 2021-02-18 18:35

    Firstly

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

    Then import in your project

    import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
    import {  faFacebookF , } from '@fortawesome/free-brands-svg-icons';
    

    Use this

    <FontAwesomeIcon icon={faFacebookF} />
    
    0 讨论(0)
  • 2021-02-18 18:37

    Install these dependencies first

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

    Create a custom library initFontAwesome.js and paste this code.

    import { library } from "@fortawesome/fontawesome-svg-core";
    import {fab, faTwitterSquare, faFacebook, faLinkedin, faGithub} from "@fortawesome/free-brands-svg-icons";
    
    function initFontAwesome() {
        library.add(fab, faTwitterSquare, faFacebook, faLinkedin, faGithub);
    }
    export default initFontAwesome;
    

    In the App.js include the following code

    import initFontAwesome from "./initFontAwesome";
    initFontAwesome();
    
    function App() {
      return (
    
       {/*---------Some code----------*/}
    
      );
    }
    export default App;
    
    

    In Home.jsx include the following code

    import React from 'react';
    import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
    
    {/*-------some Code---------*/}
    
    <FontAwesomeIcon icon={['fab', 'twitter']} />
    
    <FontAwesomeIcon icon={['fab', 'facebook']} />
    
    <FontAwesomeIcon icon={['fab', 'linkedin']} />
    
    <FontAwesomeIcon icon={['fab', 'github']} />
    
    {/*-------Some Code---------*/}
    
    This worked for me. I hope this helps!
    
    
    0 讨论(0)
  • 2021-02-18 18:40

    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.

    0 讨论(0)
  • 2021-02-18 18:42
    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

    0 讨论(0)
  • 2021-02-18 18:57

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

    0 讨论(0)
提交回复
热议问题