Francesco Meli
Francesco Meli

Reputation: 2700

integrate react and react-fontawesome

The react-fontawesome documentation suggests to create a custom library, to only include the icons one needs.

They say to do as follow:

The question is about the 2nd step: is it possible to create a separate file for the library creation? I don't like the idea of having a long list of icons in my application entry point.

What confuses me is that there isn't anything to export, since is it is only a function call (library.add). Should I export a self calling function that executes the library creation?

Upvotes: 0

Views: 161

Answers (1)

Jayffe
Jayffe

Reputation: 1279

Edit 71yv4pw3nq

Maybe you can write a file that contains your filled library :

import { library } from '@fortawesome/fontawesome-svg-core';
import { faStroopwafel } from '@fortawesome/free-solid-svg-icons';

library.add(faStroopwafel);

And in your main file, only import this library and FontAwesomeIcon:

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import "./MyLib"

function App() {
  return (
    <div className="App">
      <FontAwesomeIcon icon="stroopwafel" />
    </div>
  );
}

Edit : Thanks to @mwilkerson for the improved version

Upvotes: 1

Related Questions