09 / 12

How do you create custom actions not tied to a slice?

In Redux Toolkit, you can create actions that are not directly associated with a slice by using the createAction utility. This is useful when actions are shared across multiple slices or handled only by extra reducers.

When to Use createAction
  1. 1

    When multiple slices need to respond to the same action.

  2. 2

    When you want a standalone action not tied to any slice logic.

  3. 3

    When using createReducer or extraReducers to handle shared updates.

Example: Defining and Using a Custom Action

Here, resetTodos is a standalone action that can be dispatched anywhere in the app. It’s not defined inside a slice but can still be handled by reducers or extraReducers as part of other slices.