Perceived performance is just as critical as raw API response speed. Users expect interactions like liking a post, submitting a form, or reordering items to reflect on screen instantly.
1. The Power of React 19 useOptimistic
The `useOptimistic` hook allows client components to immediately display expected state mutations before the asynchronous Server Action finishes execution on the server.
2. Robust Rollback on Server Errors
If the Server Action fails validation or encounters a database error, React automatically reverts the UI state to the prior server-confirmed value and displays inline validation feedback.
3. Type-Safe Action Contracts with Zod
Wrapping Server Action input parameters with Zod schema validation ensures runtime type safety and sanitized data before triggering database writes.
