I am trying to use the new React Lazy and Suspense to create a fallback loading component. This works great, but the fallback is showing only a few ms. Is there a way to add an additional delay or minimum time, so I can show animations from this component before the next component is rendered?
Lazy import now
const Home = lazy(() => import("./home"));
const Products = lazy(() => import("./home/products"));
Waiting component:
function WaitingComponent(Component) {
return props => (
<Suspense fallback={<Loading />}>
<Component {...props} />
</Suspense>
);
}
Can I do something like this?
const Home = lazy(() => {
setTimeout(import("./home"), 300);
});