0

here I got an Array of objects in res, but when I set the data in State the result is an empty array.

 const [profileData, setProfileData] = useState([])

  function getData() {
    axios.get("http://192.168.29.72:5002/profile",)
    .then((response) => {
      const res =response.data

      setProfileData(res)
      console.log(profileData);
   
    }).catch((error) => {
      if (error.response) { 
        console.log(error.response)
        console.log(error.response.status)
        console.log(error.response.headers)
        }
    })}

Whats wrong here? how can I get the data in state.

sankar
  • 1
  • 1

0 Answers0