let data = [223, 34, 456, 56, 67];
function getDataFromApi(paramfromTableCell){
let postData = {data : paramfromTableCell}
let result = apiResponse(url, 'post', postData).catch((err => console.log(err)))
return result;
}
data.map((value)=>{
return(
<th>{getDataFromApi(value)}</th>
)
})
Calling a function inside table cell but it’s returning a promise. On calling a function it takes a parameter and return the name as per number but it returning promise. Is there a way to resolve it?
2
Answers
You have to
await
the promise to get the result. Otherwise you will just get the promise. So addasync
to your map function and then useawait
:It looks like you using react. You need to save your responses into a react state for that.
Here is a example code how it should look like (not tested):