I think I found the reason why this happens. It is because we are using objects as state. When you set setState({...state,hey:true}) you are setting state to a new object, which has a new address, so state changes, so it re-renders, while if you set state as this for example setState(true), this would not cause an infinite loop because it will not cause a re-render of the App component when setting its state to true when it is already true.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I think I found the reason why this happens. It is because we are using objects as state. When you set
setState({...state,hey:true})
you are setting state to a new object, which has a new address, so state changes, so it re-renders, while if you set state as this for examplesetState(true)
, this would not cause an infinite loop because it will not cause a re-render of theApp
component when setting its state totrue
when it is alreadytrue
.