(Simplified example): I have Component A
and Component B
, which are sibling components and are both lazy-loaded in App.js:
import { lazy, Suspense } from 'react';
const A = lazy(() => import('./A'));
const B = lazy(() => import('./B'));
const App = () => (
<Suspense fallback={<div>Loading...</div>}
{ someCondition &&
<A />
}
{ someOtherCondition &&
<B />
}
</Suspense>
);
Would it be possible to load B
when A
is loaded (Basically when someCondition
is true), without having to render B
until later? This way, the loading of components is grouped and my website can be uninterrupted after the first lazy load.
Thank you in advance! If someone has a solution I will mark their answer as Correct.