0
  const [confirmData, setconfirmData] = useState();
  const [loading, setLoading] = useState();  
  const [error, setError] = useState();

  useEffect(async() => {
    setLoading(true);
    const data = await axios.get('http://127.0.0.1:8081/getdata');
    console.log(data.data);
    setconfirmData(data.data);
    setLoading(false);
    console.log(confirmData)
  }, []);

I am trying to save API information with useState in ReactJS, but I can't save the API information in console.log(), but if I print the data after saving in useState, it does not.

Alex Wayne
  • 178,991
  • 47
  • 309
  • 337
  • https://stackoverflow.com/questions/67690187/useeffect-with-empty-array-doesnt-behave-as-componentdidmount/67690392#67690392 check here – SlothOverlord May 26 '21 at 08:12
  • By the way, when using useEffect with async functions you should do: useEffect(() => { async function anyNameFunction() { await loadContent(); }; anyNameFunction(); }, []); – fjplaurr May 26 '21 at 08:17

0 Answers0