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'
|
'use client'
|
||||||
|
|
||||||
import { useState } from 'react'
|
import { useState, useCallback } from 'react'
|
||||||
import { motion } from 'framer-motion'
|
import { motion } from 'framer-motion'
|
||||||
import { ChevronDown } from 'lucide-react'
|
import { ChevronDown } from 'lucide-react'
|
||||||
|
|
||||||
@@ -11,12 +11,19 @@ interface HeroSectionProps {
|
|||||||
export default function HeroSection({ heroPhoto }: HeroSectionProps) {
|
export default function HeroSection({ heroPhoto }: HeroSectionProps) {
|
||||||
const [imageLoaded, setImageLoaded] = useState(false)
|
const [imageLoaded, setImageLoaded] = useState(false)
|
||||||
|
|
||||||
|
const imgRef = useCallback((node: HTMLImageElement | null) => {
|
||||||
|
if (node && node.complete) {
|
||||||
|
setImageLoaded(true)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="relative min-h-screen flex flex-col items-center justify-center overflow-hidden">
|
<section className="relative min-h-screen flex flex-col items-center justify-center overflow-hidden">
|
||||||
{/* Background */}
|
{/* Background */}
|
||||||
{heroPhoto ? (
|
{heroPhoto ? (
|
||||||
<div className="absolute inset-0">
|
<div className="absolute inset-0">
|
||||||
<img
|
<img
|
||||||
|
ref={imgRef}
|
||||||
src={`/api/files/${heroPhoto}`}
|
src={`/api/files/${heroPhoto}`}
|
||||||
alt="Maria Malejka"
|
alt="Maria Malejka"
|
||||||
className="w-full h-full object-cover transition-opacity duration-1000 ease-in-out"
|
className="w-full h-full object-cover transition-opacity duration-1000 ease-in-out"
|
||||||
|
|||||||
Reference in New Issue
Block a user