0

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?

1110
  • 7,829
  • 55
  • 176
  • 334
  • code looks fine. what does `setDataLike` do? – TkDodo Jul 24 '23 at 15:19
  • It use axios post to update data item. I actually handle it by returning updated value and set it like it is in documentation for RQ. I didn't figure out why new data were not pulled maybe it's caching or something – 1110 Jul 25 '23 at 14:27

0 Answers0