Refine infinite scroll behavior

This commit is contained in:
Sam Becker 2023-09-10 14:41:00 -05:00
parent 2f513e2b39
commit a20bb7f927

View File

@ -15,10 +15,6 @@ export default function MorePhotos({
}) {
const router = useRouter();
if (prefetch) {
router.prefetch(path);
}
const [isPending, startTransition] = useTransition();
const buttonRef = useRef<HTMLButtonElement>(null);
@ -27,6 +23,12 @@ export default function MorePhotos({
router.push(path, { scroll: false });
}), [router, path]);
useEffect(() => {
if (prefetch) {
router.prefetch(path);
}
}, [router, path, prefetch]);
useEffect(() => {
const observer = new IntersectionObserver(e => {
if (triggerOnView && e[0].isIntersecting) {