question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warning: setState(...): Can only update a mounted or mounting component.

See original GitHub issue

Hi,

First off, thanks for an awesome lib.

We’ve experienced some issues when the animation is running but the component gets unmounted, as seen here:

screenshot 2016-11-15 17 09 52

I believe this is related to tweenValue’s (possibly also endTween’s) setState call.

Probably workaround:

componentDidMount() {
    this.setState({ isMounted: true });
}
componentWillUnmount() {
    this.setState({ isMounted: false}, () => {
        this.endTween();
    });
}
// ....


// ... not sure if needed
endTween() {
    raf.cancel(this.tweenHandle);
    if (this.state.isMounted) {
        this.setState({
            ...this.state,
            currentValue: this.props.value
        });
    }
}

// ... but this probably is:
tweenValue(timestamp, start) {
    // ....
    if (this.state.isMounted) {
        this.setState({
            currentValue: newValue,
            startTime: startTime ? startTime : currentTime,
            fromValue, currentTime
        });
    }
    // ...
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
phireskycommented, Apr 12, 2017

Fixed in #13

1reaction
t1mmencommented, Nov 25, 2016

@ameyms I’ve been unable to pin down exactly when/why this happens, I’m afraid. If I manage to figure it out, I’ll produce a gist for you.

@septs That is why I didn’t check this.isMounted() but kept it in state, though a property on the class is probably better as described in the link you pasted:

An easy migration strategy for anyone upgrading their code to avoid isMounted() is to track the mounted status yourself. Just set a _isMounted property to true in componentDidMount and set it to false in componentWillUnmount, and use this variable to check your component’s status.

Read more comments on GitHub >

github_iconTop Results From Across the Web

setState(...): Can only update a mounted or ... - Stack Overflow
Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a...
Read more >
Prevent React setState on unmounted Component
Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted ...
Read more >
Warning: setState(...): Can only update a mounted or ... - GitHub
"Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a...
Read more >
React: Stop checking if your component is mounted - Medium
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your...
Read more >
Untitled
Resolving the Can only update a mounted or mounting component warning. source. It is clear that this.setState can only be called on a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found