From the course: Learning Redux Toolkit
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Updating your store with the useDispatch hook
From the course: Learning Redux Toolkit
Updating your store with the useDispatch hook
- Let's start adding items to the cart. We will add items by clicking the add to cart button. So if we click the add card button for this spring robot item, as an example, its product ID will be added to our cartSlice. Back to our code base. Let's import the cartSlice from the data/cartSlice.js file. Now on line two, we have import cartSlice from data/cartSlice. We're also going to import the, use this patch hook from React Redux, and we'll do that on line one. - We'll use it to dispatch actions to our Redux store. So we'll gather cart action from the cartSlice and then use this batch hook to dispatch that action to our Redux store. In our home components, let's create a variable names, add to cart, and we'll do that on line seven. And assess value, we have cartSlice.actions.addToCart We can also destructure this by putting addToCart in color braces and then we have cartSlice.actions We will also need the remove from…
Contents
-
-
-
-
-
(Locked)
Creating your Redux actions and reducers3m 50s
-
(Locked)
Exporting your Redux actions and reducers1m 22s
-
(Locked)
Updating your store with the useDispatch hook2m 48s
-
(Locked)
Getting data from your store with the useSelector hook3m 32s
-
(Locked)
Displaying cart products from your Redux store6m 41s
-
(Locked)
-
-