09 / 13

How can reducers handle actions from other slices?

Handling Cross-Slice Actions with extraReducers in Redux Toolkit

Reducers in Redux Toolkit can handle actions from other slices using the extraReducers field. This allows a slice to respond to actions that are not defined within its own reducers, enabling cross-slice communication and shared state updates.

Ways Reducers Handle External Actions
  1. 1

    Use extraReducers to listen for actions defined in other slices.

  2. 2

    Use the builder callback pattern (addCase) to define logic for external actions.

  3. 3

    Respond to async actions created by createAsyncThunk, even if they originate from a different slice.

  4. 4

    Keep state updates modular while allowing coordinated behavior between slices.

Example: Responding to Actions from Another Slice

By using extraReducers, slices remain independent yet can react to global or shared actions, making your Redux architecture more modular and scalable.

Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.