I'm trying to have a fallback page that is displayed only when some data is being fetched. In NextJS's app router, they use a loading.tsx file, but I can't use that for the pages router it seems. ReactJS has Suspense fallback and there's something in NextJS called Lazy loading which uses next/dynamic, should I use this then? Would it be something like
export default function Home<HomeProps>() {
const DynamicTest = dynamic(async () => {
await Wait(2000)
return import("@/pages/Home")
}, {
loading: () => <Loading></Loading>
})
return (
<>
{<DynamicTest />}
</>
)
}
The function Wait has a setTimeout asynchronous function that halts for 2000 milliseconds to emulate fetching data. Would this be a good practice?