T
TanStack16mo ago
sunny-green

Cache is not updating

I wrote this code based on what I read at https://tanstack.com/query/v5/docs/framework/react/guides/optimistic-updatesI have a table component that has pagination that inserts the page number into the url and whenever I go to the second page and make some interaction to update the data, the data is not updated instantly, only if I reload the page. Once this happens the data is never updated again, even on page 1. I tested it before by putting an await refetch() in onSuccess and it worked correctly, but I don't know if this would be the correct way. Here is my code:
1 Reply
sunny-green
sunny-greenOP16mo ago
this is the code I was using before, but again, I don't know if it's the right approach: const { mutateAsync: updateProductsAndServicesMutation } = useMutation({ mutationFn: Api.PutProductsAndServices, onSuccess: async () => { queryClient.invalidateQueries({ queryKey: ["productsAndServices"] }); await refetchProductsAndServices(); }, });

Did you find this page helpful?