State Management · Senior · Question 35 of 75

How do you make an optimistic update with SWR's mutate?

Explanation

mutate(updateTodo(newTodo), { optimisticData: [...todos, newTodo], rollbackOnError: true, populateCache: true, revalidate: false }) shows the change immediately and reverts it if the request fails.

Further reading

Problem with a question

State Management · Senior · question 35

Test yourself

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

Take this quiz