next.js/test/integration/next-image-new/app-dir/app/ref-cleanup/page.js
page.js44 lines963 B
'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>
  )
}
Quest for Codev2.0.0
/
SIGN IN