Proyectos de Subversion LeadersLinked - SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3604 stevensc 1
import { useCallback, useRef } from 'react';
2
 
3
export const useInfinityScroll = ({ isLoading, hasMore, onIntersect }) => {
4
  const observer = useRef(null);
5
 
6
  const lastElementRef = useCallback(
7
    (node) => {
8
      if (isLoading) return;
9
      if (observer.current) observer.current.disconnect();
10
 
11
      observer.current = new IntersectionObserver((entries) => {
12
        if (entries[0].isIntersecting && hasMore) {
13
          onIntersect();
14
        }
15
      });
16
 
17
      if (node) observer.current.observe(node);
18
    },
19
    [isLoading, hasMore, onIntersect]
20
  );
21
 
22
  return { lastElementRef };
23
};