DEV Community

Discussion on: ReactJs : Any idea on how to improve this code

Collapse
 
isarisariver profile image
Marian

I usually import the package with npm "@fortawesome/fontawesome-free": "^5.14.0" and at the top of my files import "@fortawesome/fontawesome-free/css/all.css"

Then I use the Html they provide in my components.
I just use <i className="fab fa-js"></i> instead of <i class="fab fa-js"></i>. You can add additional classes to change font color, font size etc.

I can't get it to work in CodeSandbox right now, because I have never used it before :) Might try again tonight, if you still need help.

Collapse
 
pierreatwork profile image
Pierre

Thanks, good idea !

Do you know if the method i use to import FA icons only include the CSS i asked for in the build, or does it import everything in all.css ?

Collapse
 
isarisariver profile image
Marian

I think it imports everything.
When I go to my app and check "Sources" in the Developer Tools in Chrome, I find an 'all.css' file with all the font awesome icons, roughly 4.500 lines.