React · Middle · Question 44 of 75
How do you update a list after successfully creating an item via useMutation?
- ✓Correct answer: Call
invalidateQueriesfor['todos']inonSuccess - 2Reload the page via
location.reload()inonSuccess - 3Call
useQueryagain inside theonSuccesscallback
Explanation
Invalidation marks queries as stale and refetches the active ones. The alternative is to update the cache directly via setQueryData if the server returned the new object. Hooks can't be called inside callbacks.