I have this simple hook that fetch data by id:
const useGetData = (id: number) => {
return useQuery({
queryKey: ["data-item", id],
queryFn: () => getDataItemById(id),
});
};
And I have hook that set item as liked:
const useSetLike = () => {
const queryClient = useQueryClient()
return useMutation({
mutationFn: (id: number) => {
return setDataLike(id);
},
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({ queryKey: ["data-item"] });
},
})
};
But I am still getting same oobject after invalidate request.
onSuccess
is triggered normally it's just data that are not upddated.
I tried to set cacheTime: 0 in useGetData but still getting old value.
If I switch to another item and back to this I see updated valule.
Am I doing something wrong here?