Answer the question
In order to leave comments, you need to log in
How to use data received from promise?
DD, please don’t swear, but just tell me or give a link to the article if there are bookmarks where they chew on this topic, here is such an example
let dataUsers;
let url = "https://jsonplaceholder.typicode.com/users";
fetch(url)
.then((response) => response.json())
.then((data) => (dataUsers = [...data]));
Answer the question
In order to leave comments, you need to log in
If you want to
write in the style of synchronous code, use async\await
const dataUsers = await fetch(url)...
1) Do not assign the data received in the Promise to a global variable, otherwise you will get badly maintained shitty code.
2) Move the code that uses dataUsers into a separate function and call it in then
This was the first stage, the second stage - https://habr.com/ru/company/mailru/blog/269465/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question