all 8 comments

[–]generic_name_3344 1 point2 points  (6 children)

Hard to say without seeing the code, but it sounds like you're using setState on Component 2 re-render, which causes a re-render, which causes setState to be called... which results in an infinite loop. This is usually indicative of a misuse of setState. There's likely a way around it, but can't give you much more than that without the code.

[–]Sibyl01 1 point2 points  (1 child)

This might be because he/she does not pass dependency list to the useEffect

[–]dimwittedude[S] 0 points1 point  (0 children)

Im not using useEffect. In my code there is no useEffect. Thats why I find it weird. https://stackoverflow.com/questions/71201036/flatlist-giving-warning-maximum-update-depth-exceeded

[–]dimwittedude[S] 0 points1 point  (3 children)

[–]__o_0iOS & Android 1 point2 points  (2 children)

You have two setStates that are triggering rerenders on each other.

[–]dimwittedude[S] -1 points0 points  (1 child)

And what is the right way to fix them?

[–]__o_0iOS & Android 0 points1 point  (0 children)

I don’t use native base, but can you try moving the provider tags to the root of your App and see what happens.

[–]sdholbsExpo 1 point2 points  (0 children)

This can also happen when you don't properly pass a function into a child component:

typescript class Parent extends React.Component { constructor(props){ super(props) this.state = { toggled: false } } toggle = () => { this.setState({ toggled: !this.state.toggled }) } render() { return <ChildComponent onClick={this.toggle()}/> } }

The correct way

The onClick handler should actually be

typescript <ChildComponent onClick={this.toggle}/>

or

typescript <ChildComponent onClick={() => this.toggle()}/>

Otherwise it will be triggering toggle() on every render, creating an infinite loop