From 0aa4a4850d19032cc6a478be2afdacdb46295746 Mon Sep 17 00:00:00 2001 From: NNSTH <36368967+NNSTH@users.noreply.github.com> Date: Wed, 13 Nov 2019 10:27:47 +0200 Subject: [PATCH] prevent scrollListener in case of unmounted see #155 --- src/index.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index b9bf632..11a5bf8 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -66,6 +66,7 @@ export default class InfiniteScroll extends Component { private maxPullDownDistance = 0; componentDidMount() { + this._mounted = true; this._scrollableNode = this.getScrollableTarget(); this.el = this.props.height ? this._infScroll @@ -115,6 +116,7 @@ export default class InfiniteScroll extends Component { } componentWillUnmount() { + this._mounted = false; if (this.el) { this.el.removeEventListener('scroll', e => this.throttledOnScrollListener(e as MouseEvent) @@ -256,6 +258,9 @@ export default class InfiniteScroll extends Component { } onScrollListener = (event: MouseEvent) => { + if(!this._mounted) { + return; + } if (typeof this.props.onScroll === 'function') { // Execute this callback in next tick so that it does not affect the // functionality of the library.