import { useState } from 'react' import Image from 'next/legacy/image' const Page = () => { // Hoisted state to count each image load callback const [idToCount, setIdToCount] = useState({}) const [clicked, setClicked] = useState(false) return (

On Loading Complete Test

) } function ImageWithMessage({ id, idToCount, setIdToCount, ...props }) { const [msg, setMsg] = useState('[LOADING]') const style = props.layout === 'fill' ? { position: 'relative', width: '64px', height: '64px' } : {} return ( <>
{ let count = idToCount[id] || 0 count++ idToCount[id] = count setIdToCount(idToCount) const msg = `loaded ${count} img${id} with dimensions ${naturalWidth}x${naturalHeight}` setMsg(msg) console.log(msg) }} {...props} />

{msg}


) } export default Page