I am working with React on implementing a in-table button which runs an http request to decide whether to disable, something like:
<Table>
<tbody>
<tr>
<td>something1</td>
<td>something2</td>
<td>something3</td>
<Button onClick = {() => DoSomething()} disabled=
{Boolean(HTTPRequest(payload))}>
Click me!
</Button>
</tr>
</tbody>
</Table>
function HTTPRequest(payload) {
const {loading, error, data} = axios.get(API)
return data.length > 0
}
However, I notice that this does not work since the function is done before receiving a real result. I thought it has something to do with asynchrony, so I changed it to:
async function HTTPRequest(payload) {
const {loading, error, data} = await axios.get(API)
return data.length > 0
}
But it still does not work. Any suggestions will be appreciated, thank you!