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