React-Native = Invariant Violation: Maximum update depth exceeded

Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.


try:

<TouchableOpacity onPress={() => this.setState({ butPressed: true })}>

instead of

<TouchableOpacity onPress={this.setState({ butPressed: true })}>

Assigning {this.setState} to onPress without arrow function cause to render over and over again because setState casing the component to render again and then it comes again to the assignment of onPress = {}. Using arrow function instead causing to assign a function so the setState is actually doesn't happen until the function is activated. (only when onPress is activated)

Tags:

React Native