R
R
ross_nuss2022-02-05 13:20:25
css
ross_nuss, 2022-02-05 13:20:25

How to properly include fonts in ReactJs?

0

Tell me, please, where is it better to add fonts: in src or public? Is there any difference in this? And how to connect them to the project? I just started learning React, I'm trying to create my own spa and I can't figure out how to properly include fonts. I will be grateful for help)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2022-02-05
@Seasle

For example, you want the font Source Sans Pro . Install @fontsource/source-sans-pro package . In a file main.jsor main.tsimport it: or if you need a specific range of unicode characters:
import '@fontsource/source-sans-pro';
import '@fontsource/source-sans-pro/cyrillic.css';

P
profesor08, 2022-02-05
@profesor08

Fonts must be included in index.html, which is in the project. And you can place them anywhere, even in the public folder, even just connect with cdn. In .jsx, .tsx files, you do not need to include fonts, this can lead to flickering when updating some components or a page.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question