TanStackT
TanStack10mo ago
3 replies
wispy-olive

Query keeps getting triggered

Hi there, I am using a query in my beforeload function in my router. It's a function that fetches the user session, but I have an issue, that it seems that whenever I navigate anywhere on my app, the function gets called every time, sometimes multiple times:
    beforeLoad: async ({ context }) => {
        const user = await context.queryClient.fetchQuery({
            queryKey: ["user"],
            queryFn: ({ signal }) => getUser({ signal }),
        });
        return { user };
    }


This is my implementation, do I need to add more properties? I sent a screenshot of my terminal it just shows a bunch of calls from me just hovering over a link few times
CleanShot_2025-04-10_at_10.16.182x.png
CleanShot_2025-04-10_at_10.18.182x.png
Was this page helpful?