From the course: Building Modern Projects with React
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Solution: Using Thunks to update server resources - React.js Tutorial
From the course: Building Modern Projects with React
Solution: Using Thunks to update server resources
(upbeat music) - [Instructor] All right, well hopefully you gave this challenge a try. Let's take a look at the solution. So what I did is I started off by adding a mark to do as completed thunk to the thunks file. So here's what that's going to look like. I'm just going to say export const mark to do as completed. And this one, just like our delete to do thunk had to take the ID of the to do that we wanted to mark as completed as an argument and incorporate that into the asynchronous function that it returned. So here's what this is going to look like. We're going to say async dispatch and let's make sure to spell that correctly there. Dispatch and get state. And now it's going to look pretty similar to what we had here in our delete to do thunk so let's just copy and paste that for a start. And we're going to need this to be a put request. So we'll say axios.put, hopefully you figured that one out. You should have been able to just from the fact that we used get post and delete for…
Contents
-
-
-
-
-
-
-
-
-
-
(Locked)
Why do we need Redux-Thunk?1m 49s
-
(Locked)
How does Redux-Thunk work?1m 47s
-
(Locked)
The Todos API4m 6s
-
(Locked)
Keeping track of the loading state4m 8s
-
(Locked)
Loading data with Thunks10m 35s
-
(Locked)
Refactoring the to-dos reducer6m 25s
-
(Locked)
Using Thunks to create server resources7m 56s
-
(Locked)
Using Thunks to delete server resources5m 30s
-
(Locked)
Challenge: Using Thunks to update server resources38s
-
(Locked)
Solution: Using Thunks to update server resources3m 47s
-
(Locked)
-
-
-
-