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
  };
}, []);


9 Views Posted on February 19, 2022
SPONSORS