1

I am fairly new to web dev/react/js but I have been trying to request data from the backend using this code, and I can't seem to return the correct value. In the code below, it still returns 10 rather than setting the "hey" variable to the JSON data I am looking for. I'm a little out of my depth but have been searching for solutions, any help welcome!

function getViews() {
    let hey = 10;
    axios.get("http://localhost:8000/views")
    .then((response) => {
        hey = JSON.stringify(response)
        return hey
        //This return statement doesn't get called
    })
    .catch((error) => {
        console.error(error);
    })
    return hey
}

enter image description here

David
  • 208,112
  • 36
  • 198
  • 279
bagel_boy3
  • 23
  • 5

0 Answers0