Next.js · Middle · Question 27 of 75

What's the right way to do optimistic UI for a Server Action on the client?

Explanation

useOptimistic shows the expected state immediately and automatically switches back to the real one when the action finishes and fresh data arrives. revalidatePath works only on the server. router.refresh() before the action won't give instant feedback.

Further reading

Problem with a question

Next.js · Middle · question 27

Test yourself

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

Take this quiz