1. 17
    Handling Custom Actions in our Slice with extraReducers and the Builder API
    1m 52s

Handling Custom Actions in our Slice with extraReducers and the Builder API

InstructorJamund Ferguson

Share this video with your friends

Send Tweet

In our previous lessons we relied on actions generated by our createSlice function. In this lesson we build our own. Thankfully action objects are very simple. It's recommended that they follow the Flux Standard Action convention which typically looks something like this:

{
  type: "feature/action",
  payload: "some kind of data" // could be anything
}

In our case we dispatch the action { type: "cart/checkout/pending" }.

To handle arbitrary actions in our slice, we use the extraReducers property and the Builder API which provides a way to define cases for the reducer to handle without using the switch statement, so commonly found in legacy redux applications.

~ a year ago

Hello @Jamund. I have an error when using builder.addCase() => Property 'addCase' does not exist on type 'WritableDraft<CartState>'.