@replyke/ui-core-react-js
Version:
Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.
28 lines • 1.01 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { useRef, useEffect } from "react";
const InfiniteScrollTrigger = ({ onTriggered, }) => {
const commentsEndRef = useRef(null);
useEffect(() => {
const currentEndRef = commentsEndRef.current;
const observer = new IntersectionObserver(([entry]) => {
if (entry.isIntersecting) {
onTriggered();
}
}, {
root: null, // Use the document's viewport as the container
rootMargin: "0px",
threshold: 0.1, // Trigger when 10% of the target is visible
});
if (currentEndRef) {
observer.observe(currentEndRef);
}
return () => {
if (currentEndRef) {
observer.unobserve(currentEndRef);
}
};
}, [onTriggered]);
return _jsx("div", { ref: commentsEndRef, style: { height: 1 } });
};
export default InfiniteScrollTrigger;
//# sourceMappingURL=InfiniteScrollTrigger.js.map