Files
next.js/test/integration/next-image-new/app-dir/app/ref-cleanup/page.js
Janka UrygaandGitHub 4b59a7f5cd Reapply "[image, link] fix ref merging for callback refs..." (#68176) (#68199)
This reverts commit 7f677d1. Cannot reproduce the `vercel-site` failure
cited in #68176, and there's no apparent reason why this PR would cause
that
2024-07-26 09:10:30 -07:00

44 lines
963 B
JavaScript

'use client'
import Image from 'next/image'
import { useCallback, useEffect, useState } from 'react'
export default function Home() {
const [displayImage, setDisplayImage] = useState(true)
const refWithCleanup = useCallback((el) => {
if (!el) {
throw new Error(
'callback refs that returned a cleanup should never be called with null'
)
}
return () => {
console.log('callback ref was cleaned up')
}
}, [])
useEffect(() => {
setDisplayImage(false)
}, [])
return (
<main>
<h1>Should call ref cleanup on unmount</h1>
<section>
{displayImage ? (
<div style={{ position: 'relative', width: 10, height: 10 }}>
<Image
ref={refWithCleanup}
priority
fill
src="/test.jpg"
alt="alt"
sizes="10px"
/>
</div>
) : null}
</section>
</main>
)
}