Skip to content

Fix issue #6#9

Open
cube-dan wants to merge 2 commits intoiamdustan:masterfrom
perfectcube:fix-issue-#6
Open

Fix issue #6#9
cube-dan wants to merge 2 commits intoiamdustan:masterfrom
perfectcube:fix-issue-#6

Conversation

@cube-dan
Copy link
Copy Markdown

@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