"use client"; import Image from "next/image"; import React, { useState } from "react"; import { useIntersectionObserver } from "./hooks/useIntersectionObserver"; import { SkeletonWave } from "./Skeleton"; interface OptimizedImageProps { src: string; alt: string; width: number; height: number; priority?: boolean; className?: string; objectFit?: "contain" | "cover" | "fill" | "scale-down"; lazy?: boolean; } export const OptimizedImage: React.FC = ({ src, alt, width, height, priority = false, className = "", objectFit = "cover", lazy = true, }) => { const [isLoaded, setIsLoaded] = useState(false); const [ref, isVisible] = useIntersectionObserver({ threshold: 0.1, rootMargin: "50px", }); if (!lazy || priority) { return ( {alt} setIsLoaded(true)} /> ); } return (
{!isVisible ? ( ) : ( <> {!isLoaded && (
)} {alt} setIsLoaded(true)} /> )}
); };