rustclan
rustclan17mo ago

TRPC global loading page

Hey. With trpc/nextjs I'm wondering if its possible to have a global loading context/state which is used across my whole app, whenever a TRPC endpoint .isFetched property is false, it will display a "loading" symbol. Currently I have to do something like this on every page:
if (!getMailQuery.isFetched) {
return (
<AppShell navbar={<AdminNavBar selected={6} />}>
<PublicLoadingScreen />
</AppShell>
);
}
return (pageContent...)
if (!getMailQuery.isFetched) {
return (
<AppShell navbar={<AdminNavBar selected={6} />}>
<PublicLoadingScreen />
</AppShell>
);
}
return (pageContent...)
3 Replies
Nick
Nick17mo ago
useIsFetching | TanStack Query Docs
useIsFetching is an optional hook that returns the number of the queries that your application is loading or fetching in the background (useful for app-wide loading indicators). `tsx
Nick
Nick17mo ago
This is also essentially the problem that Suspense is solving, so you could enable Suspense and use that
rustclan
rustclan17mo ago
Thank you very much 🙂