I want to convert promise in to async await but I cannot find the right syntax for the function that reads the data from the response
export async function getDataFromServer(id) {
try {
const resp = await fetch('/dataget', {
credentials: "same-origin",
mode: "same-origin",
method: 'POST',
headers: { "Content-Type": "application/json" },
body: `${id}`
})
const data = await resp.json()
const handel = await function (data) {
console.log(data);
// render function
renderDataFromServer(data)
}
}
catch (err) {
if (err === "server") return
console.log(err)
}
}
renderDataFromServer()do?handelis never called. I'm not sure what the point ofconst handel = await function (data) {is. I'd just remove that line.await function(){…}doesn’t make sense. A function expression doesn’t need awaiting. What are you expecting this to do?const data = await resp.json(); renderDataFromServer(data)