Open SoHotSoup opened 6 years ago
https://github.com/Scramblelock/starwars/blob/6658875849bb1fbde758f7d057616adf3da8ed97/src/containers/App.js#L21
In this case, I would rather use something like body or parsedResponse.
body
parsedResponse
Also, because you expect the object with results at position 0, you can even write something like this:
0
Promise.all(urls.map(url => fetch(url).then(response => response.json()))) .then([{ results }] => { this.setState({ people: results }); }) .catch(error => console.log("failed", error));
the idea behind this is to take advantage of Array and Object destructuring. First, you destruct and response to get the first object of the array, then you destruct object to get the results property.
Read this: https://dev.to/sarah_chima/destructuring-assignment---arrays-16f
https://github.com/Scramblelock/starwars/blob/6658875849bb1fbde758f7d057616adf3da8ed97/src/containers/App.js#L21
In this case, I would rather use something like
body
orparsedResponse
.Also, because you expect the object with results at position
0
, you can even write something like this:the idea behind this is to take advantage of Array and Object destructuring. First, you destruct and response to get the first object of the array, then you destruct object to get the results property.