【发布时间】:2020-06-02 19:04:34
【问题描述】:
我们已经从 react 16.9 升级到 6.11,现在我们在 componentDidMount 中出现副作用时出现无限循环。
export class DataComponent extends PureComponent {
componentDidMount() {
this.props.setData({id: 'new'});
}
render() {
return <Text>{this.props.data.id}</Text>
}
}
const mamStateToProps = (state) => ({
data: state.data
});
const mapDispatchToProps = dispatch => ({
setData: (data) => dispatch(setDataAction(data));
});
const DataContainer = connect(mamStateToProps, mapDispatchToProps)(DataComponent);
代码非常简单。但是当它在循环中挂载 componentDidMount 调用时,直到最大调用堆栈。 有任何想法吗?
"react": "16.11.0",
"react-native": "0.62.2",
【问题讨论】:
-
你能在你的代码中发布
DataComponent的用法吗?这很可能是您使用它的方式。 -
是的,好像在其他地方发生了什么事。项目很大,我找不到可以放的地方......比我们升级 react 开始的时候更奇怪
标签: reactjs react-native react-lifecycle