When to Use Multiple Action Types vs Single with Payload
You'll learn: How to decide between creating specific action types for each operation versus using a generic action with a payload that specifies the field.
The Trade-Off
When designing your reducer, you face a fundamental choice:
Option A: Granular Actions
{ type: 'INCREMENT' }
{ type: 'DECREMENT' }
{ type: 'RESET' }
Option B: Generic Actions
{ type: 'UPDATE', field: 'count', value: newValue }
{ type: 'SET', payload: { count: 5, name: 'Alice' } }
Think of it like remote control buttons: You can have dedicated buttons for common actions (channel up, channel down, volume up) or a generic menu system where you navigate to settings and adjust any value.
When Multiple Action Types Win
Use specific action types when:
- The operation has unique business logic (e.g.,
APPLY_DISCOUNTcalculates percentage) - You want self-documenting code that's easy to debug
- Actions represent meaningful domain events (e.g.,
LOGIN_SUCCESS,ADD_TO_CART) - Type safety matters — TypeScript discriminated unions work beautifully
- You need to track action history for debugging or undo/redo
When Single Generic Action Works
Use a payload-based approach when:
- You're building a form with many fields that just need simple updates
- All operations follow the same pattern (just setting values)
- You want less boilerplate and fewer action creators
- The state is essentially a key-value store
The Practical Reality
Most apps use both patterns: Specific actions for complex operations, generic ones for simple updates. A form might use { type: 'UPDATE_FIELD', field, value } for input changes but { type: 'SUBMIT_FORM' } for submission logic.
Key Takeaway: Choose multiple action types when operations have distinct behavior; use generic actions with payloads only when you're truly just setting values without special logic.