I have generated "@font-face { font-family: ‘RFDewiExpanded-Thin’;font-weight: 100;
font-style: normal; src: ……..}".
How can i apply it in React without external files?
Haven’t any idea how to solve this problem.
Dynamic CCS import needs external file as i know.
2
Answers
I don’t know that you can do this natively, however, if using a CSS-in-JS library is possible you may be able to do that and keep things all to one file. Examples are JSS, Emotion, Styled JSX etc
Is there a reason you are unable to import a separate .css file? You can do dynamic things in CSS with variables and CSS imports. One method I have used / would recommend is postcss-import
You can directly define the @font-face rule in your React component.
In the useEffect hook, a new FontFace object is created. It is then added to the
document.fonts
collection.To clean up the font resources when the component unmounts, you can return a cleanup function from the useEffect hook.
Example: