T
TanStack2y ago
sensitive-blue

Use react-query with IndexDb with SSR randomly throws window not defined

I have a code similar to this:
const { data } = useQuery("idx", async () => {
const result = await indexDb.get("mykey");
return result;
})
const { data } = useQuery("idx", async () => {
const result = await indexDb.get("mykey");
return result;
})
It ramdonly throws window not defined, this is cause because I'm using it with SSR (NextJS). My current solution is to disable the fetch until the component mounts but in that case "isLoading" is false, Is there a way to have "isLoading = true" until you actually start fetching the data client side?
1 Reply
ratty-blush
ratty-blush2y ago
isPending But you obviously don’t use latest v5

Did you find this page helpful?