Problem Statement
Explain how to use createAsyncThunk and handle its lifecycle in extraReducers.
Explanation
createAsyncThunk takes a string action type prefix and an async payload creator function that performs the async operation and returns data, and you handle the generated pending, fulfilled, and rejected actions in your slice's extraReducers using builder.addCase for each lifecycle state. In the pending case, set loading to true and clear errors, in fulfilled update your data and set loading to false, and in rejected store the error and set loading to false. You can access the original arguments in meta.arg, use thunkAPI parameter for dispatch and getState access, and throw errors or return rejectWithValue for custom error handling.
