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

Can't perform a React state update on an unmounted component #93

Open
vikjovanov opened this issue Aug 16, 2020 · 6 comments
Open

Can't perform a React state update on an unmounted component #93

vikjovanov opened this issue Aug 16, 2020 · 6 comments

Comments

@vikjovanov
Copy link

I have this error, and the error tells me it's from Tooltip! My components can sometimes mount / unmount very quickly, however, I protect my state updates so that they only run if the component they are called from is mounted.

This is my code where the tooltip is defined:

<Tooltip
isVisible={isVisible}
content={...}
placement="top"
onClose={onExitModal}
backgroundColor="#00000040"
contentStyle={ownStyles.tooltip}
tooltipStyle={SHADOWS.default}
useInteractionManager={true}
showChildInTooltip={true}
allowChildInteraction={false}
childContentSpacing={20}
>
    <TooltipChildrenContext.Consumer>
    {
        ({ tooltipDuplicate }) => (
            <TouchableWithoutFeedback
                onPress={() =>{
                    this.HeartBounceRef && this.HeartBounceRef.animate(ANIMATIONS.heartBounce)
                    onPressHeart && onPressHeart()
                }}
                disabled={isButtonLoading}
            >
                <Animatable.View
                    ref={(ref) => {
                        if (!tooltipDuplicate)
                            this.HeartBounceRef = ref
                    }}
                    duration={300}
                    easing="ease-out-back"
                    useNativeDriver={true}
                >
                    {...}
                </Animatable.View>
            </TouchableWithoutFeedback>
        )
    }
    </TooltipChildrenContext.Consumer>
</Tooltip>

This is a Pure Component.

And now, the error:

Screenshot 2020-08-16 at 07 01 52

Screenshot 2020-08-16 at 07 02 04

@hudymvol
Copy link

hudymvol commented Nov 25, 2020

@jasongaare Hello, thanks for this awesome package :)

It seems like the problem is still here and this code causes memory leak:

setTimeout(() => {
    this.measureChildRect();
});

You can create a variable mounted and assign it to false on componentWillUnmount method and then check if the component is mounted this way:

if(mounted) {
  setTimeout(() => {
      this.measureChildRect();
  });
}

@jasongaare
Copy link
Owner

Hi 👋🏼

I'm not opposed to the mounted idea, if you don't mind making a PR, I'd love to get it in there!

@Sethbarrie
Copy link

Has there been any update on the mounted setstate making it into the code? I'm also running into this issue currently

@rnz269
Copy link

rnz269 commented Jan 9, 2023

Still running into this issue, unfortunately.

@saitejas-cypherd
Copy link

I'm still having this issue

@RobertMrowiec
Copy link

Still having this issue

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

No branches or pull requests

7 participants