Open
Conversation
Directly attaching an event handler that sets state will trigger thhis error. In my case using reactstrap’s <Modal> (https://reactstrap.github.io/components/modals/) Example: <Modal toggle={this.toggleModal} /> where this.toggleModal() is *doing a this.setState() What happens in my case is issue iamdustan#6 in Yellowbox hides the source of the problem, in this case directly calling the Modal.toggle function when the component is mounting which causes a React.setStateLoopOfDoom error. This patch makes sure that this._listener.remove() is a function before trying to call it, thereby allowing the real problem (state loop) to show up. *Not sure it matters but I’m using immer to set state: https://github.com/immerjs/immer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a fix for issue #6
Directly attaching a handler that calls setState will trigger this error. In my case using reactstrap’s
<Modal>(https://reactstrap.github.io/components/modals/)Example:
where this.toggleModal() is calling* this.setState()
Issue #6 in Yellowbox hides the source of the problem, in this case directly calling the Modal.toggle handler when the component is mounting which causes a React.setStateLoopOfDoom error:

Screenshot:
This patch makes sure that this._listener.remove() is a function before trying to call it, thereby allowing the real problem (set state loop) to show up.
... sorry bout the .gitignore and yarn.lock mess.
*Not sure it matters but I’m using immer to set state: https://github.com/immerjs/immer#reactsetstate-example