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);
}
}
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);
}
}
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);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us