11 / 14

What is the difference between reducers and extraReducers in a slice?

In Redux Toolkit, both reducers and extraReducers define how the slice state changes in response to actions, but they are used in different contexts.

Key Differences
  1. 1

    reducers handle actions defined within the same slice. These actions are automatically generated by Redux Toolkit.

  2. 2

    extraReducers handle actions from outside the slice, such as async thunks or actions from other slices.

  3. 3

    reducers use a simple object syntax, while extraReducers often use a builder callback for better type safety and flexibility.

Example: reducers vs extraReducers