Skip to content

Commit a87eef9

Browse files
authored
Update solution.md
Перекладено вирішення
1 parent 33e3499 commit a87eef9

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

5-network/01-fetch/01-fetch-users/solution.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
To fetch a user we need: `fetch('https://api.github.com/users/USERNAME')`.
2+
Щоб отримати інформацію про користувачів, нам потрібно викликати : `fetch('https://api.github.com/users/USERNAME')`.
33

4-
If the response has status `200`, call `.json()` to read the JS object.
4+
Якщо відповідь приходить із статусом `200`, то викликаємо метод `.json()`, щоб прочитати JS-об'єкт.
55

6-
Otherwise, if a `fetch` fails, or the response has non-200 status, we just return `null` in the resulting array.
6+
В іншому випадку, якщо `fetch` завершуєся помилкою, або код статусу у відповідді має відмінність від 200, то просто буде повернуто значення `null` у масиві результатів.
77

8-
So here's the code:
8+
Ось код:
99

1010
```js demo
1111
async function getUsers(names) {
@@ -33,8 +33,8 @@ async function getUsers(names) {
3333
}
3434
```
3535

36-
Please note: `.then` call is attached directly to `fetch`, so that when we have the response, it doesn't wait for other fetches, but starts to read `.json()` immediately.
36+
Потрібно звернути увагу на те, що виклик `.then` прикріплений до `fetch`, щоб коли відповідь отримана, то зразу починати зчитування даних за допомогою `.json()` не очікуючи завершення інших запитів.
3737

38-
If we used `await Promise.all(names.map(name => fetch(...)))`, and call `.json()` on the results, then it would wait for all fetches to respond. By adding `.json()` directly to each `fetch`, we ensure that individual fetches start reading data as JSON without waiting for each other.
38+
Якщо, було би використано `await Promise.all(names.map(name => fetch(...)))`та викликали би `.json()` на результатах запитів, то треба було би чекати поки закінчилися всі із них. Викликаючи `.json()` зразу після кожного `fetch`, ми добились того, що зчитування надісланих по кожному запиту даних відбуваєся незалежно від інших запитів.
3939

40-
That's an example of how low-level Promise API can still be useful even if we mainly use `async/await`.
40+
Це приклад того, як відносно низько-рівневе Promiese API може бути корисним, навіть якщо ми в основному використовуємо `async/await` у коді.

0 commit comments

Comments
 (0)