#Query undefined if I reload the page

2 messages · Page 1 of 1 (latest)

jade surge
#

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

This is my query:

    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?
rapid tusk
#

!session?.accessToken || !session.apiEndpoint

then this condition is likely falsy

also, please don't return undefined from the queryFn. you should see a warning that this isn't allowed