From 08c48b33ab2326ba4744f79975de4fbdaf7ea8ee Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Mon, 16 Jan 2017 15:03:40 -0800 Subject: [PATCH] Clear timeout when unmounting There may be some cases where waypoint mounts and then unmounts before this timeout has an opportunity to happen. For these cases we want to clear the timeout when the component unmounts to avoid any possible errors. --- src/waypoint.jsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/waypoint.jsx b/src/waypoint.jsx index 8c75316..3093ac4 100644 --- a/src/waypoint.jsx +++ b/src/waypoint.jsx @@ -153,7 +153,7 @@ export default class Waypoint extends React.Component { // this._ref may occasionally not be set at this time. To help ensure that // this works smoothly, we want to delay the initial execution until the // next tick. - setTimeout(() => { + this.initialTimeout = setTimeout(() => { this._handleScroll(null); }, 0); } @@ -174,6 +174,8 @@ export default class Waypoint extends React.Component { removeEventListener(this.scrollEventListenerHandle); removeEventListener(this.resizeEventListenerHandle); + + clearTimeout(this.initialTimeout); } /**