Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For the infinite scrolling feature, can add custom component when it reaches to the last item? #168

Open
tcf01 opened this issue Aug 30, 2024 · 4 comments
Labels
question Further information is requested

Comments

@tcf01
Copy link

tcf01 commented Aug 30, 2024

Currently I am using the the useInfiniteLoader function, have read the doc but I cannot see props to detect whether I can add the custom component(eg. a text component indicate users that it has reached the end / still loading for the new content...) when the user has scrolled to the end of the scrollable content.

Do I have to handle it by myself or is there any workaround? Thank you!

@tcf01 tcf01 changed the title For the infinite scrolling feature, can add components when it reaches to the last item? For the infinite scrolling feature, can add custom component when it reaches to the last item? Aug 30, 2024
@jaredLunde
Copy link
Owner

Yeah you'd have to handle that one yourself. There's no API for that available in the library

@jaredLunde jaredLunde added the question Further information is requested label Aug 30, 2024
@tcf01
Copy link
Author

tcf01 commented Sep 5, 2024

@jaredLunde Do you think is there any way to detect exactly when the user is scrolled to the bottom? I hv tried the normal way but still it is not that accurate. This is the hook function I hv atm

import { useCallback, useEffect, useState } from 'react';

export const useDetectScrolledToBottom = (node: any) => {
  const [isBottom, setIsBottom] = useState(false);

  const handleScroll = useCallback(() => {
    const { scrollTop, scrollHeight, clientHeight } = node.current;
    setIsBottom(scrollTop + clientHeight === scrollHeight);
  }, [node]);

  useEffect(() => {
    if (node?.current) {
      node.current.addEventListener('scroll', handleScroll);
      return () => node?.current?.removeEventListener('scroll', handleScroll);
    }
  }, [node, node.current, handleScroll]);
  return { isBottom };
};

@jaredLunde
Copy link
Owner

Maybe you could add a trigger element with an Intersection Observer? https://wesbos.com/06-serious-practice-exercises/scroll-events-and-intersection-observer

@tcf01
Copy link
Author

tcf01 commented Sep 6, 2024

@jaredLunde The link is broken but I found sth related. I just wonder the intersection observer needs to set a last element ref to it but how to judge it in a masonry layout?

And also if I hv implemented the intersection observer, do I still need to use the onRender function from masonic(I guess it's no?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants