parthmmm
parthmmm
TTCTheo's Typesafe Cult
Created by parthmmm on 1/24/2023 in #questions
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 });
};
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 });
};
8 replies