Course lesson
Handling Custom Actions in our Slice with extraReducers and the Builder API
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...
- Duration
- 2 min
- Access
- Free
- Transcript
- Available
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.