I have a user_id
on my state, it's looks as :
this.state ={id_user:''}
I want to get this id_user from another component, I develop it like that :
handleAjouter = (id_user) => {
this.setState({
openPopupAjout: true,
id_user: id_user
});
console.log(id_user, this.state.id_user)
}
When I run it, I get on the console :
id_user: 1258
this.state.id_user: it's empty value
But when I change the method handleAjouter
to this :
handleAjouter = (id_user) => {
this.state.id_user = id_user;
this.setState({
openPopupAjout: true
});
console.log(id_user, this.state.id_user)
}
I get on the console :
id_user: 1258
this.state.id_user: 1258
But, I get also Do not mutate state directly. Use setState()
How can I fix it ?