I'm using a React.lazy
along with Suspense
to set a loading.
const LazyComponent = React.lazy(() => {
const x = new Promise((resolve) => {
setTimeout(() => {
return resolve(import("../Components/ListContainer"));
}, 3000);
});
return x;
});
function Home() {
return (
<>
<Suspense fallback={<Loading />}>
<LazyComponent />
</Suspense>
</>
);
}
In my code, I set the timeout to 3000
, but my objective is to make it loading until it completely fetched all the data and then renders all of the data at once.
Is there a way to achieve that? Or is there a better way to set a loading?