← Back to demos

Async Data Fetching

Compare state machine vs boolean flags for managing async states.

State Machine Approach
idle
Impossible states are... impossible. Clean, predictable behavior.

Click the button to fetch data

State Machine Guarantees:

  • • Only ONE state at a time (loading OR error OR success)
  • • Transitions are explicit and validated
  • • Retry count automatically tracked in context

Key Takeaway:

With booleans, you have 2^n possible combinations (4 with 2 flags). With state machines, you have exactly N states - no invalid combinations possible.