Manage asynchronous workflows where one call depends on another’s result.

Modern Redux Toolkit (RTK) Approaches:

  1. Chain  Dispatch a second thunk from within the first thunk’s payloadCreator after the first API call succeeds. Good for linear dependencies.
  2. RTK Query: Define endpoints using createApi. Use query hooks in components. The second query hook can use the skip option to wait until data from the first query (e.g., a user ID) is available. Often the cleanest approach for API data fetching.

Use createAsyncThunk chaining:

export const fetchUserAndOrders = createAsyncThunk( 'user/fetchUserAndOrders', async (userId, { dispatch }) => { const user = await fetch(`/api/users/${userId}`).then(res => res.json()); await dispatch(fetchOrders(user.id)); return user; }
);