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.
Using Thunks to delete server resources - React.js Tutorial
From the course: Building Modern Projects with React
Using Thunks to delete server resources
- [Instructor] Alright, so now that we've created a thunk for creating todos, the next thing we're going to do is create a thunk for deleting todos. So this should be pretty straightforward. What we're going to do is go back into our thunks file and just as a side note here, we're going to be making delete requests to this endpoint here, which is going to include the id of the todo, right? That's why we added this id property to make it easier to do that. So let's give this a try. What we're going to do is go into thunks.js We're going to export a new function called deleteTodo And this is going to take the id of the, todo that we want to delete, which we'll call todoId and return an asynchronous function that takes dispatch and get state as arguments. And now this is going to look pretty similar, to what we had in our createTodo thunk. So I'm just actually going to copy a lot of the code from there and paste it in here and adjust the indentation of course. And there's just a few…
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)
-
-
-
-