My dashboard page requests a reading from an ESP32: function getTemp() { let result; fetch('/api/temp').then(r => r.json()).then(d => { result = d.value; }); return result; }. Calling getTemp() always gives undefined, although a console.log inside the callback prints the correct value a moment later.
I tried returning the value from inside the then callback, and also a while loop that waits for result to be set; the loop just hangs the page. How do I get the value out of an asynchronous call?




