Skip to content

Image Component doesn't forwardsRef #18398

@piotrzaborow

Description

@piotrzaborow

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

  1. Add Image component to your page
  2. Add ref via useCallback hook
  3. 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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions