Skip to content

Conversation

@androettop
Copy link

@androettop androettop commented Jul 15, 2025

This PR introduces a useInfiniteScroll hook to trigger data loading when the user scrolls near the bottom of the page

related issue: #18

*/
const useInfiniteScroll = (callback: () => void) => {
useEffect(() => {
const target = document.getElementById('skeleton');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you refactor this to take in a ref instead, and make useInfiniteScroll generic to any scrollable container that can pass a ref into it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it that way initially, but I changed it because it made it much more complex to send the reference from the layout to the page, and because the scrollable area is always the same I left it that way.
But if you prefer, I can do it that way.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other thing I can do is to make the results table scrollable (but 100% height), so it is visually the same but I can control the scroll in the scope of the page

const scrollHeight = target.scrollHeight;
const clientHeight = target.clientHeight;

if (scrollHeight - scrollTop <= clientHeight + DEFAULT_THRESHOLD) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's called DEFAULT_THRESHOLD, then please also expose an optional threshold?: number arg that callers can override

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants