@Alex-Archer-I
Posted
Hi!
Basically the async-await pattern and fetch-than chain doing the same thing, it's just different syntax. At first you need to declare function with async
keyword. Than you can use await
in those parts of the function which must be executed with potential delay.
// Here you declare that this is async function
const fetchAdvice = async () => {
// Than you use await keyword anytime you need to perform async code.
// The function will not be executed further till it get the response.
let response = await fetch('https://api.adviceslip.com/advice');
// You can perform some code here if need.
// Here is an analog of this part - .then(response => response.json())
const advice = await responce.json();
// And work with advice content.
};
Hope this helps. If you have any questions fell free to ask. Good luck =)
Marked as helpful
@Alex-Archer-I Thank you very much for your help, I'm happy to analyze my code, I had studied asynchronous js but I forgot about await
@Alex-Archer-I
Posted
@Adrianocode19
Glad I could help =)
Marked as helpful