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

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