Which fix removes the bug?
async function getData() {
const res = fetch("/api");
return res.json();
}
- Remove
asyncfrom the function - Change
res.json()tores.json - Add
awaitbeforefetch("/api") - Wrap the body in
try/catch
fetch returns a promise that must be awaited first.