TanStackT
TanStack3y ago
1 reply
rubber-blue

Query undefined if I reload the page

I'm using rq with nextjs. I'm using the pages router and I'm having the following problem:

This is my query:

const classrooms = useQuery({
    queryKey: ["classrooms"],
    queryFn: () => {
      if (!session?.accessToken || !session.apiEndpoint) {
        return;
      }

      return apiClient.get(
        "classrooms",
        session.accessToken,
        session.apiEndpoint
      );
    },
    initialData: rosterData || [],
  });


rosterData is the data I pass to the page as a prop from getServerSideProps.

What happens is: If I navigate to the page using the router, everything works perfect, but if for some reason y reload the page using F5 for example, the query stops working and returns undefined.

Does anyone have insight in why is this happening?
Was this page helpful?