I am confused why this code returns an array of promises, while the last bit returns actual data (array of objects):
( async() => {
const [user, posts] = await Promise.all([
fetch('https://jsonplaceholder.typicode.com/users'),
fetch('https://jsonplaceholder.typicode.com/posts')
]).then( ([res,res2]) => [res.json(),res2.json()]
).then( ([d1,d2]) => {
console.log(d1,d2);
});
})();
// Promise {[[PromiseStatus]]: "resolved", [[PromiseValue]]: Array(10)}
// Promise {[[PromiseStatus]]: "resolved", [[PromiseValue]]: Array(100)}
When I use fetch by itself, I get the data I want:
fetch('https://jsonplaceholder.typicode.com/posts')
.then( (res) => res.json() )
.then( (data) => console.log(data)); // returns array of objects
// (100) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, ...