Overview
The counter machine demonstrates:- Using context to store a count value
- Using assign actions to update context
- Handling multiple event types
- Stateless machines (no explicit states)
Machine Definition
Implementation
Complete Example
Key Concepts
- Context: Stores extended state data (the count value)
- assign(): Action creator for updating context
- Stateless machines: Machines without explicit states can still respond to events
- Immutability: Context updates create new objects, preserving immutability
When to Use Context
Use context for:- Numeric values (counters, timers)
- Form data
- API responses
- User information
- Any data that changes over time