Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
7 replies
parthmmm

Trpc not invalidating query

Hi, I'm trying to invalidate my query after the mutation runs but nothing happens. When I look at the rq devtools, I see no changes. I logged the invalidate and a promise that is fulfilled gets returned but my query is not invalidated. I searched for the issue here which led me to add the async await. I've tried a few different way but no luck. Thanks for any help

const followInfo = trpc.user.getFollowInfo.useQuery({ username });

  const followMutation = trpc.user.followUser.useMutation({
    onSettled: async () => {
      await utils.user.getFollowInfo.invalidate({ username });
    },
  });
  const unfollowMutation = trpc.user.unfollowUser.useMutation({
    onSettled: async () => {
      await utils.user.getFollowInfo.invalidate({ username });
    },
  });

  const unfollow = () => {
    unfollowMutation.mutate({ username });
  };

  const follow = () => {
    followMutation.mutate({ username });
  }; 
Was this page helpful?