Sử dụng Promise.all với fetch

promise,fetch,async

Sử dụng Promise.all hiệu quả sẽ làm cho hiệu suất của code chúng ta tăng lên đáng kể. Và mã sau đây giúp các bạn có thể get được nhiều data mà không ảnh hưởng tới performance.

Tips: Tìm hiểu sâu về cách sử dụng Promise

async function getFullPost(){
  return await Promise.all([
     fetch('/post'),
     fetch('/comments')
  ]);
}
const [post, comments] = getFullPost();

Có thể bạn đã miss một số snippets code

using javascript callback style error handling

promise in javascript

promise in javascript

Promise.all là gì?

Promise.all là gì? Hiểu và sử dụng promise all trong những trường hợp nào trong vòng 1 phút.

Await in a for loop

How to Await in a for loop

using Typescript callback style error handling