State Management · Middle · Question 28 of 75
How do you refresh the list after useMutation creates an item?
- ✓Correct answer: Call
queryClient.invalidateQueries({ queryKey: ['todos'] })inonSuccess - 2Call
useQueryagain insideonSuccess - 3Reload the page with
location.reload()
Explanation
Invalidation marks matching queries stale and refetches active ones. Alternatively write the returned object into the cache with setQueryData. Hooks can't be called inside callbacks.