JS Built-ins
redux-toolkitcreateAsyncThunkintermediate

Full extraReducers Builder

πŸ“– Usage Example
builder
  .addCase(loadItems.pending, state => { state.status = 'loading' })
  .addCase(loadItems.fulfilled, (state, action) => {
    state.items = action.payload
    state.status = 'succeeded'
  })
  .addCase(loadItems.rejected, (state, action) => {
    state.status = 'failed'
    state.error = action.error.message
  })

Handling all three lifecycle actions gives you a complete async state machine: idle β†’ loading β†’ succeeded or failed.

Full extraReducers Builder

Handle all three thunk lifecycle actions in one slice. This covers pending (loading), fulfilled (success), and rejected (failure).

Challenge: Handle all three lifecycle actions for loadItems:

  • pending β†’ status = 'loading'
  • fulfilled β†’ items = payload, status = 'succeeded'
  • rejected β†’ status = 'failed', error = message
πŸ’‘ Hints (3)
  • β€’ Chain `.addCase()` for all three lifecycle action creators.
  • β€’ For rejected: `action.error.message` holds the error string.
  • β€’ This pattern (idle β†’ loading β†’ succeeded/failed) is the standard async state machine.