09 / 14

What’s the purpose of extraReducers in createSlice()?

The extraReducers field in createSlice() lets a slice respond to actions that weren’t defined inside its own reducers. It’s commonly used to handle actions generated by async thunks or actions from other slices.

When to Use extraReducers
  1. 1

    To handle actions from createAsyncThunk() (like pending, fulfilled, and rejected).

  2. 2

    To respond to actions defined in other slices.

  3. 3

    To keep reducers modular while still reacting to shared global actions.

Example: Using extraReducers with createAsyncThunk