componentWillReceiveProps //已经被废弃
componentDidUpdate //推荐使用
getDerivedStateFromProps// 推荐使用
componentDidUpdate(prevProps){
if(prevProps.item.width!==this.state.width){
this.setState({
width:prevProps.item.width,
})
}
}
//如果条件不存在必须要返回null
static getDerivedStateFromProps(props, current_state) {
if(props.item.width!==current_state.width){
return {
width:props.item.width,
}
}
return null
}