Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

javascript - new FontFace() doesn't work in create react app

I wanna make a dynamic font loader

import './App.css';

function App() {

  const font = async () => {
    try {
      const font = new FontFace('ko', 'url(ko.ttf)');
      const loadedFont = await font.load();
      console.log(loadedFont);
    } catch (err) {
      console.error(err);
    }
  };

  return (
      <div className="App">
        <button onClick={font}>Click</button>
      </div>
  );
}

export default App;

I got an error when I click on the button

Failed to decode downloaded font: http://localhost:3001/ko.ttf
OTS parsing error: invalid version tag
DOMException: A network error occurred

It's too simple code.. what's wrong and how can i fix it

question from:https://stackoverflow.com/questions/65932322/new-fontface-doesnt-work-in-create-react-app

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...