Reusable React Hook for Custom Scroll Logic and Pagination

I got tired of rewriting the same scroll logic… so I built a reusable React hook 👇 In one of my projects, I had multiple places where I needed: → Detect when a user is near the bottom → Trigger API calls (pagination / infinite scroll) → Handle different containers (not just window scroll) Initially, I was repeating this logic everywhere. So I extracted it into a custom hook: 👉 useTableScrollPagination What it does: • Works with both containers and tables (AG Grid in my case) • Lets me control when to trigger (75%, 90%, etc.) • Prevents duplicate API calls while loading • Keeps scroll position intact after data updates The biggest win? 👉 I no longer think about scroll logic — I just reuse it. I know there are libraries for infinite scroll, but in real-world apps: → Custom containers → Complex UI structures → Different trigger behaviors …often need a more flexible approach. Curious — how are you handling infinite scroll in your apps? Library or custom solution? #ReactJS #FrontendDevelopment #TypeScript #DeveloperExperience

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories