1. 程式人生 > >react 子元件監聽props 變化

react 子元件監聽props 變化

componentWillReceiveProps //已經被廢棄  



getDerivedStateFromProps// 推薦使用


//如果條件不存在必須要返回null   
static  getDerivedStateFromProps(props, current_state) {
        if(props.item.width!==current_state.width){
            return {
                
                width:props.item.width,
            }
        }
        return null
}