From the course: Building Modern Projects with React

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Using thunks to update server resources

Solution: Using thunks to update server resources

From the course: Building Modern Projects with React

Start my 1-month free trial

Solution: Using thunks to update server resources

(bouncy music) - [Narrator] Okay, so let's take a look at one possible solution to marking a to do is completed on the server using thunks. The way I started off was by opening up thunks js, and adding a new thunk called markTodoAsComplete request, export const markTodoAsCompleted request. And this thunk took an id as an argument, and returned an async function that took dispatch as an argument. The same as the rest of our thunks. And for the body if this thunk, I pretty much just copied and pasted the body from the removeTodoRequest thunk. The main changes I made here, was first of all to change the url that we're sending the request to, by adding /completed to the end of it. And then for the method, instead of sending a delete request, I sent a post request. And then I renamed this from removedTodo, to updatedTodo. And finally, the action I dispatched was markTodoAsCompleted with the updatedTodo that we got back…

Contents