#Query keeps getting triggered

3 messages · Page 1 of 1 (latest)

hoary rune
#

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

digital cloak
#

beforeLoad runs in serial whearas the loaders all run in parallel, which is why anything that does a fetch usual goes in loader

#

I'd say if you use ensureQueryData that'll cut down on the fetches