Post(s) tagged Await
How to use Async Await inside react useEffect() hook
The following method is a safe way to use await and async inside react useEffect() hook
const getUsers = async () => {
const users = await fetchUsers();
setUsers(users);
};
useEffect(() => {
getUsers(); // run it, run it
return () => {
// this now gets called when the component unmounts
};
}, []);
Posted on February 19, 2022