score:0
To achive this, I render my loader inside body tag in _document.js
file.
I thought a bit how to detect moment when all of my page content loaded (content, images, fonts, styles) and i got idea to load my fonts in footer, after all content, images and styles are loaded.
I did it, by implementing useEffect()
hook in my footer file, and load fonts like this:
const Footer = () => {
React.useEffect(() => {
let fonts = [];
if (typeof window !== "undefinded") {
// Initialize Font
fonts.push(
new FontFace("font1", "url(/fonts/font1.ttf)", {
style: "normal",
weight: "400",
})
);
fonts.push(
new FontFace("font2", "url(/fonts/font2.ttf)", {
style: "bold",
weight: "700",
})
);
// Load all fonts
for (var font in fonts) {
document.fonts.add(font);
font.load();
}
// Disable loading screen when all font are loaded
document.fonts.ready.then(function (e) {
document.getElementById("loading-screen").style.display = "none";
});
}
}, []);
return <>...Footer content</>;
};
Source: stackoverflow.com
Related Query
- Is there way to add "Loading screen" when DOM rendering in Next.js app?
- Is there a way to tell when your react app page is done loading the page / assets?
- In React Native on iOS, is there a way to determine when an app is resumed? Such as an onResume event?
- Next JS : Loading Screen While the dom is rendeing
- Is there a way to add an icon when sort direction is null on Material UI's DataGrid headers?
- Is there a way to update history location of app registered in single spa when url changes?
- Is there any way to prohibit the screen from scrolling when moving input type=range?
- React app is not rendering at all when loading HTML page that contains it
- What is the best way to show loading screen on every components when component is not fully rendered WITHOUT REPEATING CODES
- How to hide dom element for App when loading another component
- React: App not rendering to screen when wrapped in React.Component
- React JS PWA app not opening without internet when opening from add to home screen
- Is there a way to modify a value when its changed after rendering without useEffect
- Is there any way to set url when I click button in next js
- Home Component is not rendering when the app loads on Github Pages but loading on Localhost
- Is there a way to halt loading a react app until authentication status is resolved?
- React - Is there a way to check when page is done loading after route change?
- Is there a way that reactJS hides the text when he goes into the next line?
- React - Display loading screen while DOM is rendering?
- When to use a react framework such as Next or Gatsby vs Create React App
- Is there any way to see names of 'fields' in React multiple state with React DevTools when using 'useState' hooks
- Loading Screen on next js page transition
- How to add logical if statement when rendering React components?
- is there a way to build a react app in a single html file?
- Most efficient way of rendering JSX elements when iterating on array of data in React
- Is there a way to detect when data used by a query is evicted from the Apollo Client cache?
- Is there way to track user current location within service workers in PWA while app is in sleep mode?
- React show loading spinner while DOM is rendering
- Is there some way to avoid HTML escaping of text children when calling React.createElement?
- Is there a way to make ReactJs SEO friendly without using Next or Gatsby?
More Query from same tag
- react-pdf loads file from disk but not url
- React/Redux: Remove from cart not working, not getting any error
- How to find specific items in an array in React/Framer?
- Options in render not loading React JS
- Uploading an image file with Express.js, React, and MySQL
- CodeSandbox.io <img> tag not loading image
- Can't get API URL to reroute to right address: React Hooks
- Add param to current URL without reloading or redirecting with react router
- Creating a circular border radius on multiple child components
- React / Redux how split input values with comma
- Input text no longer editable when using register with react-hook-form
- Parsing error: Unexpected token, expected ";" whenever I add a constructor?
- React-Toggle side menu className
- Using self made npm package in react. Failed to compile
- The requested URL /about-us was not found on this server
- Pass click event to nested component - React | Material-UI
- Apollo client 2 with React couldn't make query
- React Useeffect running when page loads
- How to setState with the array that has push method?
- A string ref, "grid", has been found within a strict mode tree
- React-Jest Unit test an external module method that affects state
- useContext returns undefined in child component
- How to get ajax response in react?
- Why props are undefined even while I render component conditionally?
- I want to make a FlatList who render all datas
- Unable to get form values in React-Bootstrap's Formgroup Component
- Axios doen't send any data to php
- How to get a value form a child component to a parent component in reactjs?
- How to prevent html2canvas to take screenshots after show my pdf?
- how to update react hooks array state?