0

We have upgraded from react 16.9 to 6.11, and now we have infinite loop when side effect in 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);

The code is totally simple. But when it is mounting componentDidMount calling in loop until maximum call stack. Any ideas?

"react": "16.11.0",
"react-native": "0.62.2",
Maksim Zarechnyi
  • 407
  • 3
  • 16

1 Answers1

1
componentDidMount() {
    this.props.setData({id: 'new'}); //add .props
}
Michael Mishin
  • 586
  • 2
  • 8