'use client'; import { useEffect } from 'react'; import { useInView } from 'react-intersection-observer'; import { Loader2 } from 'lucide-react'; import { cn } from '@/lib/utils'; interface InfiniteScrollProps { onLoadMore: () => void; hasMore: boolean; isLoading: boolean; loadingText?: string; endMessage?: string; className?: string; } export function InfiniteScroll({ onLoadMore, hasMore, isLoading, loadingText = 'Loading more items...', endMessage = 'No more items to load', className }: InfiniteScrollProps) { const { ref, inView } = useInView({ threshold: 0, rootMargin: '100px 0px', }); useEffect(() => { if (inView && hasMore && !isLoading) { onLoadMore(); } }, [inView, hasMore, isLoading, onLoadMore]); return (
{isLoading && (

{loadingText}

)} {!hasMore && !isLoading && (

{endMessage}

)}
); }