Browse Source
Prevent unmounted setState and remove listener on StickyBackToTop
master
meriadec
7 years ago
No known key found for this signature in database
GPG Key ID: 1D2FC2305E2CB399
1 changed files with
3 additions and
1 deletions
-
src/components/StickyBackToTop.js
|
|
@ -49,6 +49,7 @@ class StickyBackToTop extends PureComponent<Props, State> { |
|
|
|
const { scrollContainer } = this.props.getGrowScroll() |
|
|
|
if (scrollContainer) { |
|
|
|
const listener = () => { |
|
|
|
if (this._unmounted) return |
|
|
|
const { scrollTop } = scrollContainer |
|
|
|
const visible = scrollTop > this.props.scrollThreshold |
|
|
|
this.setState(previous => { |
|
|
@ -59,11 +60,12 @@ class StickyBackToTop extends PureComponent<Props, State> { |
|
|
|
}) |
|
|
|
} |
|
|
|
scrollContainer.addEventListener('scroll', listener) |
|
|
|
this.releaseListener = () => scrollContainer.addEventListener('scroll', listener) |
|
|
|
this.releaseListener = () => scrollContainer.removeEventListener('scroll', listener) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
componentWillUnmount() { |
|
|
|
this._unmounted = true |
|
|
|
this.releaseListener() |
|
|
|
} |
|
|
|
|
|
|
|