question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Page loaded below waypoint

See original GitHub issue

Is there a way to detect if the page has been loaded below a waypoint? Basically let’s say you have a waypoint that you reach as you scroll down. This triggers onEnter and onLeave, however if you have a page where you start below the waypoint, these won’t get triggered. Is there a way to detect the current scroll position relative to the waypoint?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
threehamscommented, Aug 6, 2018

componentDidMount solutions leave a window of time (1/3 to 1/2 second in my testing) between the component mount and Waypoint’s resize handlers. If someone scrolls during that time, your app state will still be out of sync.

Although onLeave doesn’t get called on initial render, onPositionChange does. As a workaround, you can take advantage of that. This code causes onEnter and onLeave to mirror each other, and avoids fighting with the setTimeout inside react-waypoint.

import ReactWaypoint from "react-waypoint";

class Waypoint extends Component {
  render() {
    const { onLeave, onPositionChange } = this.props;
    return (
      <ReactWaypoint
        {...this.props}
        onPositionChange={position => {
          // In the case where the page is already scrolled down at the point when
          // the waypoint initializes, handle a "no previous, current above/below" by
          // calling onLeave with the position.
          //
          // See: https://github.com/brigade/react-waypoint/issues/253
          if (
            typeof position.previousPosition === "undefined" &&
            position.currentPosition !== ReactWaypoint.inside &&
            onLeave
          ) {
            return onLeave(position);
          }
          onPositionChange && onPositionChange(position);
        }}
        onLeave={onLeave}
      />
    );
  }
}
1reaction
trotzigcommented, Jun 10, 2018

@dzucconi I traced that log down to this test case: https://github.com/brigade/react-waypoint/blob/68d1948b26509941ec601057d1df989bb68366de/test/waypoint_test.jsx#L874

I’ve pushed a PR addressing the confusion around the error message here: https://github.com/brigade/react-waypoint/pull/255. You can safely ignore the error log.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Waypoints.js: check if element is in view on page load
This way, the handler function will be called upon pageload if the element in question is in the viewport. Below is a working...
Read more >
react-waypoint - npm
React Waypoint can be used to build features like lazy loading content, infinite scroll, scrollspies, or docking elements to the viewport on ...
Read more >
Page loaded below waypoint - - Bountysource
Basically let's say you have a waypoint that you reach as you scroll down. This triggers onEnter and onLeave , however if you...
Read more >
GPS GPX Batch Waypoint and Route Creator - L-36.com
This page works for about 500 waypoints. ... or you can start with the output from another program that outputs .gpx files like...
Read more >
jQuery code messing up rest of code - Forums - CSS-Tricks
(By messing up I mean I don't believe code below fires.) ... Is the Waypoint library loaded before this JS is called?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found