简体   繁体   中英

Font-Awesome icon does not show in my ReactJS website

I'm trying to use a font next to my website's header in a react project I`m working on but it does not show.

I have imported the font-awesome package via yarn and imported the css of it in my index.js file but it does not show in my header.

index.js:

import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import "../node_modules/bootstrap/dist/css/bootstrap.min.css";
import "../node_modules/font-awesome/css/font-awesome.min.css";

ReactDOM.render(<App />, document.getElementById("root"));

Header Component:

import React, { Component } from "react";

export default class Header extends Component {
  render() {
    return (
      <div>
        <div className="col-md-6 m-auto">
          <h1 className="text-center mb-3">
            <i className="fas fa-book-open"> </i>
            English Dictionary
          </h1>
        </div>
      </div>
    );
  }
}

Only the text of the header is shown. I checked the browser for any errors and it did not show any, also when i inspect the page i see the element.

<i className="fas fa-book-open"> </i>

I hope any of you can help me, thanks!

You will need to follow these steps to use font-awesome with react :

Install these dependencies:

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

Make necessary imports where you need to use them:

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faTimes } from '@fortawesome/free-solid-svg-icons'

Use in JSX:

<FontAwesomeIcon icon={faTimes} />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM