Here is a function that makes an Axios.get() request:
const mentorName = (value) => {
try {
const res = Axios.get(
`${BASE_URL}/api/v1/consultations/${value}`
)
if (res.status !== 200 || res.data.status !== "success") {
console.log(res)
return
}
} catch (error) {
console.log(error)
}
}
The below is the output of the console:
Please Click here to see console output
Now, I want to access res.data.data.consultant but When I try to do so. It says that res.data is not valid. This maybe becuase its wrapped in a promise. Please help me be telling How to access it???
EDIT:
Used async/await as suggested:
const mentorName = async (value) => {
try {
const res = await Axios.get(
`${BASE_URL}/api/v1/consultations/${value}`
)
if (res.status !== 200 || res.data.status !== "success") {
console.log(res)
return
}
} catch (error) {
console.log(error)
}
}
Async/await gives the following error: Objects are not valid as a React child (found: [object Promise]).
EDIT 2:
mentorName is used inside array.map((row, index)). I am quite sure that nothing is wrong in calling the function.
<TableCell align="left">
{mentorName(row.consultantID)}
</TableCell>