import { useRef, useEffect } from "react";
export const useInfiniteScroll = ({ element, fetch }) => {
const loader = useRef(fetch);
const observer = useRef(
new IntersectionObserver(
(entries) => {
const first = entries[0];
if (first.isIntersecting) {
loader.current();
}
},
{ threshold: 0.5 }
)
);
useEffect(() => {
loader.current = fetch;
}, [fetch]);
useEffect(() => {
const currentElement = element;
const currentObserver = observer.current;
if (currentElement) {
currentObserver.observe(currentElement);
}
return () => {
if (currentElement) {
currentObserver.unobserve(currentElement);
}
};
}, [element]);
};
-
Notifications
You must be signed in to change notification settings - Fork 0
horchatajs/lazy-loading-react
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Ejemplo de lazy loading en imagenes con React JS
Topics
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published