I am getting undefined returned value when I press button.
<Button btnType="outline" onClick={LockUnlockAccountHandler}>
lock client’s account
</Button>
const LockUnlockAccountHandler = async () => {
const status = await LockUnlockAccount(detailData?.userId, detailData?.blocked ? 'UNLOCK' : 'LOCK');
console.log(status)
if(status){
setDetailData({
...detailData,
blocked: !detailData.blocked
})
}
}
Status value is undefined in above function which should be true or false from below function.
export async function LockUnlockAccount(clientID, dataVal) {
var config = {
method: 'post',
url: endpoint.lockAccount + clientID + "/status" + endpoint.key,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
data : qs.stringify({
'status': dataVal
})
};
axios(config)
.then(function (response) {
//console.log(JSON.stringify(response));
if (response.status === 200) {
toast('succès');
return true;
}
return false;
})
.catch(function (error) {
console.log(error);
toast('error');
return false;
});
}
axios(config)->return axios(config)or justawaitthe result and return from the function itself. You've marked the function as async but don't useawaitanywhere in it.