Build an optimistic React update that recovers cleanly
8 steps · about 2 h 18 min · Intermediate
- Model the temporary optimistic state (reference, React documentation, 20 min)
Represent the expected result separately from confirmed data while an action is pending.
- Track the action result (reference, React documentation, 18 min)
Keep the latest confirmed result and pending state connected to the action that produced them.
- Disable only the submitting path (reference, React documentation, 14 min)
Read the nearest form submission state so duplicate actions are prevented without disabling the whole page.
- Keep action buttons intentional (reference, MDN Web Docs, 20 min)
Give submit and retry buttons explicit types so optimistic state cannot be duplicated by an accidental form action.
- Reason about repeated submissions (reference, MDN Web Docs, 18 min)
Decide whether retrying the operation is safe before offering automatic recovery after an uncertain response.
- Cancel obsolete requests (reference, MDN Web Docs, 18 min)
Combine user cancellation and timeout signals so a late response cannot overwrite newer confirmed state.
- Expose pending regions (reference, MDN Web Docs, 14 min)
Tell assistive technology that a region is being updated before its final content is ready.
- Announce and explain rollback (reference, MDN Web Docs, 16 min)
Connect the failed action to persistent error text and a usable recovery path.