0
Argument of type '() => Promise<void>' is not assignable to parameter of type 'EffectCallback'.
  Type 'Promise<void>' is not assignable to type 'void | Destructor'
  useEffect(async () => {
    const users = await axios.get("https://randomuser.me/api/?page=1&results=10&nat=us");
    setUsers(users.data.results);
  }, []);

I am getting this error while using async in react native

Phil
  • 157,677
  • 23
  • 242
  • 245

1 Answers1

0

You can try with the following example:

useEffect(() => {
  // declare the data fetching function
  const fetchData = async () => {
    const data = await fetch('https://yourapi.com');
  }

  // call the function
  fetchData()
    // make sure to catch any error
    .catch(console.error);
}, [])
Quyen Nguyen
  • 271
  • 2
  • 9