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.