Next.js · Middle · Question 27 of 75
What's the right way to do optimistic UI for a Server Action on the client?
- ✓Correct answer: With
useOptimisticwhile the action is running - 2With
router.refresh()before calling the action - 3With
revalidatePathin the client component
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.