We have just migrated from react query v3 to react query v4. Official react query document to migrate mentions onSuccess is no longer called from setQueryData.
See below for more details.
https://tanstack.com/query/v4/docs/framework/react/guides/migrating-to-react-query-4#onsuccess-is-no-longer-called-from-setquerydata
There are few places in our app where we call setQueryData
from onSuccess
callback like below.
const useUpdateTitle = (id) => {
const queryClient = useQueryClient()
return useMutation({
mutationFn: (newTitle) =>
axios
.patch(`/posts/${id}`, { title: newTitle })
.then((response) => response.data),
onSuccess: (newPost) => {
queryClient.setQueryData(['posts', id], newPost)
},
})
}
Such use cases are mostly while using useMutation
hook and none while using useQuery
hook.
Is this ok or will this cause any problem?