Reactjs componentWillReceiveProps未获得最新的道具
我与react和redux合作。我想用mapDispatchToProps存储windowWidth,并通过props读取另一个组件中的值。不幸的是,componentWillReceiveProps从未获得最新的值,而是之前的值。怎么了 反应,雷杜 容器:Reactjs componentWillReceiveProps未获得最新的道具,reactjs,redux,Reactjs,Redux,我与react和redux合作。我想用mapDispatchToProps存储windowWidth,并通过props读取另一个组件中的值。不幸的是,componentWillReceiveProps从未获得最新的值,而是之前的值。怎么了 反应,雷杜 容器: that.props.selectWidth({windowWidth: windowWidth}); 组成部分: componentWillReceiveProps: function () { const windowWidt
that.props.selectWidth({windowWidth: windowWidth});
组成部分:
componentWillReceiveProps: function () {
const windowWidth= that.props.selectedWidth.windowWidth;
}
应该是
componentWillReceiveProps: function (nextProps) {
const windowWidth= nextProps.selectedWidth.windowWidth;
}
在组件运行时将接收props
函数此。在更新之前,props
仍然是当前的props。因此,您需要使用nextrops
参数,该参数可以传递到componentWillReceiveProps
中,以便在组件完成更新后获得哪些道具
应该是
componentWillReceiveProps: function (nextProps) {
const windowWidth= nextProps.selectedWidth.windowWidth;
}
在
组件运行时将接收props
函数此。在更新之前,props
仍然是当前的props。因此,您需要使用nextrops
参数,该参数可以传递到componentWillReceiveProps
中,以便在组件完成更新后获得哪些道具 没有足够的细节来重现问题。没有足够的细节来重现问题