0

Why does "console.log(data)" print undefined. I've attempted to learn more about async javascript but I'm still confused

function updateData() {
       axios.get("http://localhost:8080/profile/get-status")
           .then((res) => {
               setData(res.data.data)
           });
       console.log(data);
   }
  • Also, you are calling `console.log(data);` before you send the request – Konrad Oct 18 '22 at 21:46
  • 1
    mostly it's a standard async problem (logging before the request finishes), moving the `console.log` inside the `then` would illustrate the `useState` side of things as per the duplicate – pilchard Oct 18 '22 at 21:50

0 Answers0