Font Awesome 5 use social/brand icons in React

后端 未结 5 1571
南笙
南笙 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条回答
  •  猫巷女王i
    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---------*/}
    
    
    
    
    
    
    
    
    
    {/*-------Some Code---------*/}
    
    This worked for me. I hope this helps!
    
    

提交回复
热议问题