T
TanStack14mo ago
ambitious-aqua

Invalidating query

Hi, need some help with a GET request I'm invalidating right after a PATCH, but it just happens for the first time, then I don't see it in devtools (React Query). I've tried to set cacheTime to 0, but it doesn't work.
const endpoint = `user/${userId}/account/${accountLinkId}`
const { mutateAsync: saveUserPreference } = useMutation({
mutationFn: async (preference: UserPreference) => {
return await restRequest({
endpoint: `${USER_PREFERENCES_API}/${endpoint}`,
variables: [preference],
method: 'PATCH',
})
},
onSettled: async () => {
// Invalidate the GET request to ensure it runs again.
await queryClient.invalidateQueries({ queryKey: [endpoint] })
},
})
const endpoint = `user/${userId}/account/${accountLinkId}`
const { mutateAsync: saveUserPreference } = useMutation({
mutationFn: async (preference: UserPreference) => {
return await restRequest({
endpoint: `${USER_PREFERENCES_API}/${endpoint}`,
variables: [preference],
method: 'PATCH',
})
},
onSettled: async () => {
// Invalidate the GET request to ensure it runs again.
await queryClient.invalidateQueries({ queryKey: [endpoint] })
},
})
Does anyone have any ideas ?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?