Q:

async await class component react

async function fetchFunction() {
  try{
	const response = await fetch(`http://url.com`);
	const json = await response.json();
  }
  catch(err) {
    throw err;
    console.log(err);
  }
}
1
  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);
  }
0

New to Communities?

Join the community