Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMark Franklin
3,162 PointsPurpose of .then for put request?
When adding the put request functionality to the saveTodos method of the dataService, what is the purpose of the .then(function(result){todo = result.data.todo}) ?
I originally built it without including this and everything worked just fine. It doesn't appear to actually do anything that I can see, what's it for?
3 Answers
Steven Parker
231,268 PointsI haven't taken this course yet myself, but normally a then method is called on a promise to establish the function to be performed when it gets (or if it has already been) resolved.
If leaving out had no adverse effects, then I would guess that having the todo variable set to todo value contained in the returned data isn't important to the rest of the program.
Shawn Stern
6,123 PointsWould appreciate a response to this question. My app also has no immediately noticeable ill effects from completely removing the .then from that part of saveTodos... Why was it put there?
matthewharrington2
Courses Plus Student 13,219 PointsI think that it's just there to return a value(the object that was saved) so that you know that the put worked. You can console.log(result.data.todo); to see the object. While it doesn't seem to serve much of a purpose in this app, maybe he included it to show how you can access the res object( from router.put in the src/api/index.js file) of the put.