React · Middle · Question 44 of 75

How do you update a list after successfully creating an item via useMutation?

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.

Further reading

Problem with a question

React · Middle · question 44

Test yourself

Take the React · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz