'use client' import Image from 'next/image' import { useState } from 'react' interface OptimizedImageProps { src: string alt: string caption?: string width?: number height?: number priority?: boolean className?: string } export function OptimizedImage({ src, alt, caption, width = 800, height = 600, priority = false, className = '', }: OptimizedImageProps) { const [isLoading, setIsLoading] = useState(true) const [hasError, setHasError] = useState(false) if (hasError) { return ( Failed to load image {caption && {caption}} ) } const imageElement = ( setIsLoading(false)} onError={() => setHasError(true)} placeholder="blur" blurDataURL="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='300'%3E%3Crect width='400' height='300' fill='%2318181b'/%3E%3C/svg%3E" /> {isLoading && ( )} ) // Always use to avoid invalid HTML nesting in tags // This prevents hydration mismatches between server and client return ( {imageElement} {caption && {caption}} ) }
tags // This prevents hydration mismatches between server and client return ( {imageElement} {caption && {caption}} ) }