通过 props 的调度动作最终在下一个 js 中超出了最大深度
dispatch action via props end up in maximum depth exceeded in next js
我试图通过 Next.js 中的道具调用我的动作,但它一直超过最大深度,我不明白为什么。
UNSAFE_componentWillReceiveProps(nextProps) {
let rate_updated = [...this.props.previousArray];//copying store value to local variable
for (let i = 0; i < this.props.crypto_head_coins.length; i++) {
//my code here
}
this.props.update_rate_array(rate_updated) // calling action to set array value in state
this.setState({ rate_updated }); // setting array to state
}
这就是我映射它们的方式
const mapDispatchToProps = dispatch => ({
update_rate_array: Array => dispatch(update_rate_array(Array))
});
const mapStateToProps = state => ({
previousArray: state.crypto_head_update
});
如下检查this.props
是否等于nextProps
,不同时才执行
UNSAFE_componentWillReceiveProps(nextProps) {
if(this.props !== nextProps){
let rate_updated = [...this.props.previousArray];//copying store value to local variable
for (let i = 0; i < this.props.crypto_head_coins.length; i++) {
//my code here
}
this.props.update_rate_array(rate_updated) // calling action to set array value in
state
this.setState({ rate_updated }); // setting array to state
}
}
我试图通过 Next.js 中的道具调用我的动作,但它一直超过最大深度,我不明白为什么。
UNSAFE_componentWillReceiveProps(nextProps) {
let rate_updated = [...this.props.previousArray];//copying store value to local variable
for (let i = 0; i < this.props.crypto_head_coins.length; i++) {
//my code here
}
this.props.update_rate_array(rate_updated) // calling action to set array value in state
this.setState({ rate_updated }); // setting array to state
}
这就是我映射它们的方式
const mapDispatchToProps = dispatch => ({
update_rate_array: Array => dispatch(update_rate_array(Array))
});
const mapStateToProps = state => ({
previousArray: state.crypto_head_update
});
如下检查this.props
是否等于nextProps
,不同时才执行
UNSAFE_componentWillReceiveProps(nextProps) {
if(this.props !== nextProps){
let rate_updated = [...this.props.previousArray];//copying store value to local variable
for (let i = 0; i < this.props.crypto_head_coins.length; i++) {
//my code here
}
this.props.update_rate_array(rate_updated) // calling action to set array value in
state
this.setState({ rate_updated }); // setting array to state
}
}