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!
If you installed the Free Font Awesome version but try adding Pro icons to your web pages, they won't show. The solution to this is either you use the alternative free icons or upgrade to a Pro subscription/license.
To solve the error "Module not found: Error: Can't resolve 'react-icons'", make sure to install the react-icons package by opening your terminal in your project's root directory and running the command npm install react-icons and restart your dev server.
Once you've installed all the packages you need for your project, there are two ways you can use Font Awesome 5 with React.
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} />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With