Skip to content

Commit

Permalink
Clear timeout when unmounting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lencioni committed Jan 16, 2017
1 parent 0cdb374 commit 08c48b3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/waypoint.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -174,6 +174,8 @@ export default class Waypoint extends React.Component {

removeEventListener(this.scrollEventListenerHandle);
removeEventListener(this.resizeEventListenerHandle);

clearTimeout(this.initialTimeout);
}

/**
Expand Down

0 comments on commit 08c48b3

Please sign in to comment.