TanStackT
TanStack2y ago
2 replies
spotty-amber

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;
})


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?
Was this page helpful?