1.父组件的值不是异步的时候,可以通过componentDidMount 钩子函数拿到最新值
componentDidMount() {
const {active} = this.props;
console.log(active)
}
2.当父组件的值是异步的时候子组件就拿不到最新值
使用 componentWillReceiveProps 就可以拿到父组件的值
componentWillReceiveProps(nextProps, nextContext) {
const {active} = nextProps;
console.log(active);
}