Inside of there the first thing we want to do is call e.preventDefault. That's going to take an argument e, which is a type React.FormEvent. Underneath our onQuantit圜hanged() function, type function onCheckout(). Go ahead and save this file and open up Cart.tsx. Any time a component dispatches the cart/checkout/pending action, we'll be able to handle it in this reducer. Then in the body type state.checkoutState = "LOADING". It takes in a state and an action and we use arrow function syntax here. Go ahead and type builder.addCase() and for the type say "cart/checkout/pending" and the second argument is our reducer function. The builder API provides very similar functionality to the switch statement, which is commonly used in reducers, but instead of switching through all the cases by action type, you define cases like this. This is going to be a function that takes an argument called builder. Down below reducers add a new property called extraReducers. Both of these things are totally possible. How can I handle actions in this reducer that weren't generated here? What if I want to have a custom action creator? You might be wondering if it's possible to untangle those two steps. Jamund Ferguson: The reducer's option in Redux toolkit's createSlice() function provides a convenient syntax for creating reducer functions and generating their associated actions in a single step.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |