I want to experiment with Suspense
and Lazy
.
For this, I was thinking in defer o delay the load of the component for certain time, however, I could not do it.
What I was doing is using setTimeout() at componenDidMount(), then update the state and return that piece of state. But, this is not working as I expected.
Can anyone help me delaying the load of a component with Lazy
without using browsers tools to fall in Suspense
fallback?
If I understood your question right, something like this should work for you:
const Component = React.lazy(async () => {
await new Promise(resolve => setTimeout(resolve, YOUR_DELAY));
return import('./Component');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With