Warning: setState(...): Can only update a mounted or mounting component.
See original GitHub issueHi,
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:
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:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fixed in #13
@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: