lint_coding_agent / server /templates /level_8 /InfiniteScroll.js
anonajay's picture
Upload folder using huggingface_hub
c7b3de4 verified
Raw History Blame Contribute Delete
696 Bytes
import React, { useEffect, useRef } from 'react';
const InfiniteScroll = ({ loadMore }) => {
const loaderRef = useRef(null);
useEffect(() => {
const observer = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting) {
loadMore();
}
});
if (loaderRef.current) {
observer.observe(loaderRef.current);
}
// BROKEN: Missing cleanup function!
// The observer will keep watching the DOM even if
// this component is destroyed.
}, [loadMore]);
return <div ref={loaderRef}>Loading more posts...</div>;
};
export default InfiniteScroll;