i was searching so many ways to solve this, but no one works, setState
still not working inside the componentWillReciveProps
method here is my code :
export class Detail extends React.Component
{
constructor(props)
{
super(props);
this.state = {
ids: 'ger'
}
}
componentWillReceiveProps(nextProps) {
this.setState({ ids: nextProps.data }, () => {
console.log(nextProps.data+"=this id")
});
}
render()
{
return (
<View>
<Text>{this.state.ids}</Text>
</View>
);
}
}
if i do console.log(nextProps.data+"=this id")
it can return the id that i want to update to this.state.ids
. But in the <Text>{this.state.ids}</Text>
in the render still shows the default value of this.state.ids
('ger') , means that this.state.ids
did not updated in the componentWillReceiveProps
.