04 / 18

4. What are the lifecycle actions automatically created by createAsyncThunk?

Lifecycle Actions in createAsyncThunk

When you create an async thunk using createAsyncThunk in Redux Toolkit, it automatically generates three distinct action types that represent the lifecycle of an asynchronous operation — pending, fulfilled, and rejected.

Lifecycle Actions Created Automatically
  1. 1

    1. pending: Dispatched when the async function is first called. Typically used to set a loading state or show a spinner in the UI.

  2. 2

    2. fulfilled: Dispatched when the async operation completes successfully. The returned data becomes the action’s payload.

  3. 3

    3. rejected: Dispatched when the async operation fails due to an error, timeout, or rejection. Contains the error message for debugging or display.

Example: Handling Lifecycle Actions in a Slice

These lifecycle actions allow developers to handle loading, success, and error states in a predictable and structured way, reducing boilerplate and improving async flow management.