createAsyncThunk
createAsyncThunk is a utility from Redux Toolkit that streamlines writing asynchronous thunks. It generates a thunk action creator and automatically emits three action types that reflect the lifecycle of an async request: pending, fulfilled, and rejected. This helps manage loading state and error handling in reducers with less boilerplate.
Usage: createAsyncThunk(type, payloadCreator, options?). The type is a string prefix such as 'users/fetchById'. The payloadCreator is
Generated actions can be consumed in a slice via extraReducers. For example: fetchUserById = createAsyncThunk('users/fetchById', async (id,
Notes: createAsyncThunk handles promise rejections and can integrate with TypeScript typings. If you throw an error
Overall, it offers a standardized pattern for common async flows in Redux stores and is often used