Skip to content

Is it possible to load a custom font only when online? #1294

Answered by joaoreynolds
joaoreynolds asked this question in Q&A
Discussion options

You must be logged in to vote

I kind of answered my own question. I tried put this logic in useEffect so it would only run once. This was throwing errors about missing props from react-pdf. So I had to move it out of the hook. I'm registering fonts and creating the StyleSheet in the component on every render. Not ideal, but it works 🤷‍♂️. If anybody has a better idea, let me know! I think if there was a font fallback similar to how the browser behaves it would be best.

  // This runs on every render in the document component

  // font files are imported like: import nunitoRegular from './fonts/Nunito-Regular.ttf'
  if(window.navigator.onLine){
    Font.register({
      family: 'Nunito',
      fonts: [
        { src: n…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by joaoreynolds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant