DEV Community

Discussion on: Top 4 Mistakes in React Interviews

Collapse
 
ronicastro profile image
Roni Castro • Edited

I believe the code on problem 3 will not work, because 'await' is only allowed within async functions.
This would work:

  useEffect(() => {
    const fetchData = async () => {
         const res = await fetch("https://someurl.com");
         const json = await res.json();
         setList(json);
     }
    fetchData();
  }, []);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
andyrewlee profile image
Andrew Lee

Yup! Fixing it now..