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 });
};
4 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
cje
cje2y ago
you shouldnt need the await if you post a minimal reproduction repo i could take a look most likely your querykey is incorrect / too specific
shiroyasha9
shiroyasha92y ago
does the username variable of yours ever change? I'm guessing that either it does not, or if using a state, the old value gets passed in leading to no change in data
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server