Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
3 replies
typedef

TRPC's useContext does not invalidate query.

Still dont know why useContext is not working for me (using .refetch, .invalidate on utils does nothing):

I can confirm that onSuccess gets called. It also doesnt work even if I remove the enabled option. It invalidates when I put an override on createTRPCNext but I really don't want to invalidate all the queries in the cache.
const utils = trpc.useContext();
const websites = trpc.website.getWebsites.useQuery(undefined, {
    enabled: isAuthenticated,
  });
 const updateWebsite = trpc.website.updateWebsite.useMutation({
    onSuccess: async () => {
      await utils.website.getWebsites.invalidate();
    },
  });
image.png
Was this page helpful?