react-waypoint
react-waypoint copied to clipboard
WayPoint OnEnter triggers multiple times when scrolling (drag)
trafficstars
I've noticed that if I click the up arrow Waypoint works correctly but if I drag it runs multiple times.
Im trying to create infinite load going upward like a chat screen
I have to do the undefined check at first to load if screen isn't full, which gets the scroll bar to show
handleEnd = (previousPosition, currentPosition, fetchMore, cursor) => {
if (
this.messagesRef &&
this.messagesRef.current.scrollTop < 100 &&
this.state.hasMoreItems &&
this.state.loading !== true
) {
if (
(!previousPosition && currentPosition == Waypoint.inside) ||
previousPosition === Waypoint.above
) {
console.log("HERE");
this.fetchData(fetchMore, cursor);
}
}
};
<Waypoint
onEnter={({ previousPosition, currentPosition }) =>
handleEnd(
previousPosition,
currentPosition,
fetchMore,
messages[messages.length - 1].createdAt
)
}
/>