Answer the question
In order to leave comments, you need to log in
Is there any way to find out if the page's media files have loaded without using the load event handler?
Hello.
Such a thing is that I show the preloader (which is created by react), until the media files are loaded and the responses from the requests come
function App(props){
const [requestLoading, setRequestLoading] = useState(true);
const [mediaLoading, setMediaLoading] = useState(true);
useEffect( () => {
async function setDependences(){
/ some code
}
async function setObjects(){
/ some code
}
async function checkUser(){
/ some code
}
window.addEventListener('load', () => setMediaLoading(false) );
Promise.all([ setDependences(), setObjects(), checkUser() ])
.then( () => setRequestLoading(false) );
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<Fragment>
<Preloader loading={ requestLoading || mediaLoading } />
<Header />
{ requestLoading === false ? <Pages /> : false }
</Fragment>
);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question