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

Prevent React setState on unmounted Component #12

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

Prevent React setState on unmounted Component #12

wants to merge 3 commits into from

Conversation

zicrox
Copy link

@zicrox zicrox commented Mar 27, 2019

Although there is a method "stopWatching" which is called in "componentWillUnmount" and clear the interval, is possible that the native method "measure" async callback is returned with the component already unmounted.

index.js Outdated Show resolved Hide resolved
@@ -37,11 +39,13 @@ exports.InViewPort = class extends Component {
return
}
this.myview.measure((x, y, width, height, pageX, pageY) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check also here that component is mounted before starting timeout (failsafe).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically it is already failsafe "startWatching" is called only in "componentDidMount" and "componentWillReceiveProps" these lifecycle methods are invoked after the component are mounted

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being public methods they can be called from outside...

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.

2 participants