await fetch in react 1

await fetch in react

async function fetchFunction() {
	const response = await fetch(``);
	const json = await response.json();
  catch(err) {
    throw err;

Here is what the above code is Doing:
1. We’re using the async keyword to declare an asynchronous function.
2. We’re using the await keyword to wait for the response from the fetch call.
3. We’re using the await keyword again to wait for the json() method’s promise to resolve.
4. We’re using the try…catch statement to catch any errors that may occur in the try block.

Similar Posts