Fix hero image not showing when cached (check img.complete)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useState, useCallback } from 'react'
|
||||
import { motion } from 'framer-motion'
|
||||
import { ChevronDown } from 'lucide-react'
|
||||
|
||||
@@ -11,12 +11,19 @@ interface HeroSectionProps {
|
||||
export default function HeroSection({ heroPhoto }: HeroSectionProps) {
|
||||
const [imageLoaded, setImageLoaded] = useState(false)
|
||||
|
||||
const imgRef = useCallback((node: HTMLImageElement | null) => {
|
||||
if (node && node.complete) {
|
||||
setImageLoaded(true)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<section className="relative min-h-screen flex flex-col items-center justify-center overflow-hidden">
|
||||
{/* Background */}
|
||||
{heroPhoto ? (
|
||||
<div className="absolute inset-0">
|
||||
<img
|
||||
ref={imgRef}
|
||||
src={`/api/files/${heroPhoto}`}
|
||||
alt="Maria Malejka"
|
||||
className="w-full h-full object-cover transition-opacity duration-1000 ease-in-out"
|
||||
|
||||
Reference in New Issue
Block a user