I'm using Reactjs 16.10.2 to make Website. But I can't setState.
First I passed function as a props of a component:
getStepFour = (data)=>{
this.setState({
tenCaThi:data.tenCaThi,
ngayThi:data.ngayThi,
gioBatDau:data.gioBatDau,
gioKetKetThuc:data.gioKetKetThuc,
phongThi:data.phongThi,
});
console.log('data receipt four: ', data);
console.log('state after set: ', this.state.tenCaThi);
}
<ChiaCaThi getStepFour={this.getStepFour}/>
Then I used it to get data in ChiaCathi like this:
componentWillUnmount = ()=>{
const data = {
tenCaThi:this.state.tenCaThi,
ngayThi:this.state.ngayThi,
gioBatDau:this.state.gioBatDau,
gioKetKetThuc:this.state.gioKetKetThuc,
phongThi:this.state.phongThi,
}
console.log('data in chiacathi: ', data)
this.props.getStepFour(data);
}
For some setState was not working. State after set is null.