react-waypoint icon indicating copy to clipboard operation
react-waypoint copied to clipboard

WayPoint OnEnter triggers multiple times when scrolling (drag)

Open developdeez opened this issue 7 years ago • 2 comments
trafficstars

I've noticed that if I click the up arrow Waypoint works correctly but if I drag it runs multiple times.

developdeez avatar Nov 11 '18 23:11 developdeez

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);
      }
    }
  };

developdeez avatar Nov 11 '18 23:11 developdeez

  <Waypoint
            onEnter={({ previousPosition, currentPosition }) =>
              handleEnd(
                previousPosition,
                currentPosition,
                fetchMore,
                messages[messages.length - 1].createdAt
              )
            }
          />

developdeez avatar Nov 11 '18 23:11 developdeez