#Understanding whether a fetch is made on the server

3 messages · Page 1 of 1 (latest)

normal sluice
#

Hi there,

Sorry if this is a noob question. I have a call that I only intend to make client-side (don't want it during SSR) and am trying to figure out whether a fetch is being made.

export const useUser = () => {
    const getCurrentUser = trpc.auth.getCurrentUser.useQuery(undefined, {
        refetchOnWindowFocus: false
    });

    console.log(getCurrentUser.isFetching);

    return {
        ...getCurrentUser,
        user: getCurrentUser.data
    };
};

I can see that during SSR isFetching gets set to true, which implies I am making an unneeded fetch on the server? I don't want to use hydration or initialData or anything for this one, just make the call client-side.

#

Is an option just to do something like: enabled: typeof window !== "undefined"? Do I need to add that?

hardy void
#

queries don't run on the server unless you expclicitly prefetch, or you use suspense and have a framework that can do streaming (like next13+ app dir)