Optimistic UI cập nhật UI ngay lập tức trước khi server confirm, giả định success.
- Nếu server thất bại, rollback về state trước.
- Cải thiện perceived performance.
- Implement: update local state trước khi gọi API, trong catch block rollback state và hiển thị error.
- React 19 useOptimistic hook simplifies pattern này.
Optimistic UI updates the UI immediately before the server confirms, assuming success.
- If the server fails, it rolls back to the previous state.
- This improves perceived performance significantly.
- Implementation: update local state before calling the API; in the catch block, roll back state and show the error.
- The React 19 useOptimistic hook simplifies this pattern.