Any way to reference a specific waypoint in the onEnter/onLeave handler?
See original GitHub issueI have a series of waypoints marking important boundaries on a long, scrolling page. I’d like them all to fire the same onEnter/onLeave handler rather than writing individual handlers for each Waypoint. Would it be possible to pass the key
attribute or the id
of the waypoint itself as part of the data object these handlers receive?
Issue Analytics
- State:
- Created 7 years ago
- Comments:8
Top Results From Across the Web
handler option • Waypoints - I Make Web Things
Any function. The handler option is the whole point of Waypoints. This is the function that executes when a waypoint is crossed. This...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the follow-up @andremalkine! I’m going to close this issue without any actions, as I think we’ve figured out a good-enough workaround for you and others who might run into the same issue.
@trotzig I have a page with 5 viewport filling “sections”. As the user scrolls, I’m interested in knowing when each new section enters and leaves the viewport. There is an arbitrary amount of content above them, and they can each overflow the viewport and be different heights if needed, so having waypoints is very handy/convenient.
I think the real motivation behind my question was the fact that each enter/leave triggers a very simple, similar action of declaring which section you’re “in”, 0-4. That’s it. Writing that simple behavior over and over just felt odd, and I always try to spawn anonymous functions when rendering.
I like your memoization suggestion, it’s a nice compromise between the two. You may still wind up writing a series of separate but nearly identical functions, but you avoid the aforementioned spawning.