刚开始不知道这个方法有参数,所以造成很多不可预料的问题,经过查资料发现获取最新参数要使用方法的参数来接收
例如:
nextProps为传入的参数,this.props为之前传入的参数
componentWillReceiveProps(nextProps){ if(nextProps.checked !==this.props.checked){ this.setState({ checked:nextProps.checked }); } }
刚开始不知道这个方法有参数,所以造成很多不可预料的问题,经过查资料发现获取最新参数要使用方法的参数来接收
例如:
nextProps为传入的参数,this.props为之前传入的参数
componentWillReceiveProps(nextProps){ if(nextProps.checked !==this.props.checked){ this.setState({ checked:nextProps.checked }); } }