Answers for "async await class component react"

2

await in react in function component

const here = async () => {
	console.log("here we go");
}
Posted by: Guest on June-09-2021
1

await fetch in react

async function fetchFunction() {
  try{
	const response = await fetch(`http://url.com`);
	const json = await response.json();
  }
  catch(err) {
    throw err;
    console.log(err);
  }
}
Posted by: Guest on October-03-2020
0

async await class component react

async componentDidMount() {
    // when react first renders then it called componentDidMount()
    const response = await fetch('https://jsonplaceholder.typicode.com/users');
    const json = await response.json();
    console.log(json);
  }
Posted by: Guest on October-21-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language