1. 17
    Save New Records on The Server with Redux Thunk and Fetch
    6m 38s

Save New Records on The Server with Redux Thunk and Fetch

Andy Van Slaars
InstructorAndy Van Slaars

Share this video with your friends

Send Tweet

We’ll use fetch and an async action creator to save updated data to the server and update the UI with the result of the update once the save has completed successfully.

ed leach
ed leach
~ 3 years ago

In the fetch POST body we are sending the javascript object with name and completed properties.

In the .then(res => res.json()) is the fetch just returning the same back if it is successful? Is this typical of a POST request or is it set up somewhere in this json-server setup?

Duy Nguyen
Duy Nguyen
~ 2 years ago

I have the same question as @ed did. How do we know what is gonna return back in .then()? Or this is the default behavior?

bitsubatsu
bitsubatsu
~ 2 years ago

Could you explain why (in clip 17) you decided to change the TodoForm component into a class component please?

bitsubatsu
bitsubatsu
~ 2 years ago

I have the same question as @ed did. How do we know what is gonna return back in .then()? Or this is the default behavior?

I think you will always need to get something back from a create (POST) because json-server will allocate the new todo an id (we don't pass the id to the createTodo() function) which is required as a key in the component and also later on when deleting it. You can see this by adding a todo and then looking at it, where it has been added at the end of db.json.