This video is available to students only

Using Asynchrnous Calls in Redux Part 2

In this lesson, we're going to make our application use redux toolkit

Using asynchronous calls in Redux Part 2#

Let's start implementing our async functions now. We can start with the ShowCourses component. As you know, we are using the addToCart function here and on the description page, and now we have centralized the call of this function in our basketSlice. So that we don't have to repeat the code so many times, I can simply get rid of the function, and instead of using this, I can use addBasketItemAsync function which will accept courseId as the parameter and the value of which is course.id, which means we don't need agent and setBasket here.

client/src/components/ShowCourses.tsx

Let's implement the same inside our description page. We can get rid of addToCart function and rather use dispatch and addBasketItemAsync method with parameter courseId. Let's check if both of them work fine in the browser. When we try from the homepage, it works. Also, when we try from the description page, it works as before.

client/src/pages/Description.tsx

Start a new discussion. All notification go to the author.