JS Built-ins
redux-toolkitcreateAsyncThunkintermediate

Handling Fulfilled State

πŸ“– Usage Example
builder.addCase(loadPosts.fulfilled, (state, action) => {
  state.items = action.payload
  state.loaded = true
})

The fulfilled handler receives the resolved value as action.payload β€” assign it directly to state with Immer.

Handling Fulfilled State

The fulfilled action carries the resolved value as action.payload. Use it to store fetched data in your slice.

Challenge: Create a loadPosts thunk and update items and loaded state on fulfillment.

postsSlice.reducer(undefined, loadPosts.fulfilled(['post1','post2'], 'req'))
// β†’ { items: ['post1', 'post2'], loaded: true }
πŸ’‘ Hints (3)
  • β€’ `action.payload` in a fulfilled handler is the value returned by your async function.
  • β€’ With Immer you can write `state.items = action.payload` directly.
  • β€’ Construct the fulfilled action manually for tests: `loadPosts.fulfilled(payload, requestId)`.