I have a userId
array and I need to show the list of names related to that array. I want to call API call inside the render
method and get the username. But this is not working. How can I fix this issue?
Below is my render
method:
render(){
...
return(
<div>
{this.state.users.map(userId => {
return (
<div> {this.renderName(userId )} </div>
)
})}
</div>
)
...
}
Below is the renderName
function:
renderName = (userId) => {
axios.get(backendURI.url + '/users/getUserName/' + userId)
.then(res => <div>{res.data.name}</div>)
}