I have a function that Is executed in componentDidMount() , because it does an API call, and I need the info received for the render.
componentDidMount() {
this.setState({
email: this.props.email
});
this.getPermissionsList();
this.getPermissionsValue(); //this one
}
Now, this function has the following issue
getPermissionsValue(){
console.log('/user/'+this.props.userId+'/permission') //At the moment of the execution, this.props.userId is empty
API.get('/user'+this.props.userId+'/permission')
.then(response => {
console.log(response)
this.setState({
permissionValue : response.data
}, () => {
console.log(this.state.permissionValue)
});
})
}
But in my render, I can see the this.props.userId value.
render(){
return <p>{this.props.userId}</p>
}
How can I wait for that prop before rendering?
EDIT: This is how the prop is being sent to the child from the parent
In the parent component I have a child component in the render
<EditUserModal ...a lot of props.... userId={this.state.rowId} email={this.state.selectedMail} handleChangePass={this.handleChangePass} ....more props..../>
That rowId is assigned this way in the parent component:
In my render I have this
<Table
className="table"
filterable={['Email']}
itemsPerPage={8}
currentPage={0}
sortable={true}
>
{users.map((row) => {
return (
<Tr className={row.className}>
<Td column="Email">{row.email}</Td>
<Td column="Edit" ><FontAwesomeIcon className="editIcon" onClick={()=> this.showModal(row.id, row.email)} icon={faEdit} /></Td>
</Tr>
)
})}
</Table>
where the onclick calls
showModal(rowId, rowEmail) {
this.setState({
showModal: true,
rowId: rowId,
selectedMail: rowEmail
}, () => {
// console.log("clicked show modal")
// console.log(this.state.showModal)
});
}
And thats where the rowId state value is set