How to include a Font Awesome icon in React's render()

前端 未结 15 1647
刺人心
刺人心 2020-12-04 06:30

Whenever I try to use a Font Awesome icon in React\'s render(), it isn\'t displayed on the resulting web page although it works in normal HTML.

         


        
15条回答
  •  爱一瞬间的悲伤
    2020-12-04 06:47

    Alexander's answer from above really helped me out!

    I was trying to get social accounts icons in the footer of my app I created with ReactJS so that I could easily add a hover state to them while also having them link my social accounts. This is what I ended up having to do:

    $ npm i --save @fortawesome/fontawesome-free-brands
    

    Then at the top of my footer component I included this:

    import React from 'react';
    import './styles/Footer.css';
    import FontAwesomeIcon from '@fortawesome/react-fontawesome';
    import {faTwitter, faLinkedin, faGithub} from '@fortawesome/fontawesome-free-brands';
    

    My component then looked like this:

    
      
    
    

    Worked like a charm.

提交回复
热议问题