Answers for "await fetch in react"

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