-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Closed
Milestone
Description
Bug report
Describe the bug
Refs aren't properly supported in Image.
import React, { useState, useCallback } from 'react'
import Image from 'next/image'
const NextImage = ({ src }) => {
const [width, setWidth] = useState(0)
const [height, setHeight] = useState(0)
const ref = useCallback((node) => {
console.log(node)
}, [])
return <Image ref={ref} src={src} width={width} height={height} />
}
This code shows that Image does not forwardRef to img DOM element.
To Reproduce
- Add Image component to your page
- Add ref via
useCallback
hook - Try to do something within callback function
Expected behavior
Image component should pass ref function to img element.
System information
- OS: macOS
- Browser (if applies) [Chrome, Safari]
- Version of Next.js: 10.0.0
- Version of Node.js: 15.0.0
paales, kylemcd, rokinsky, colepeters, dkodeit and 49 more