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

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