Skip to content

Fix a faulty setState call when container could be unmounted in future #54

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

Merged
merged 3 commits into from
Dec 3, 2018

Conversation

darekg11
Copy link
Contributor

Hello, we have been using this great library but there is a issue when you use HeaderImageScrollView inside a View that also has onLayout callback attached then rotating the device will cause the error to come up in React-Native warning box stating that setState can't be used on unmounted component.

This is happening because:

onContainerLayout = () => {
    if (!this.container) {
      return;
    }
    this.container.measureInWindow((x, y) => this.setState(() => ({ pageY: y })));
};

The actual callback with this.setState call might indeed happen when the component is unmounted.
Therefore I have added additional guard inside that callback to make sure that setState won't fire if container does not exist anymore.

@darekg11 darekg11 changed the title Fix an fauly setState when container could be unmounted in future Fix a faulty setState call when container could be unmounted in future Nov 22, 2018
@Nhacsam
Copy link
Contributor

Nhacsam commented Dec 3, 2018

Thanks for you contribution :-)

@Nhacsam Nhacsam merged commit 51146b1 into bamlab:master Dec 3, 2018
@darekg11
Copy link
Contributor Author

darekg11 commented Dec 3, 2018

Thank you for merging 👍
Are you planning to release new version any time soon? I would love to switch to a official npm distribution in my package.json instead of using my forked github repo :)

@Nhacsam
Copy link
Contributor

Nhacsam commented Jan 18, 2019

@darekg11
Copy link
Contributor Author

Thank you @Nhacsam 👍

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