Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #6 #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

cube-dan
Copy link

@cube-dan cube-dan commented Aug 18, 2019

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:

<Modal toggle={this.toggleModal} />

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:
image

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant