Skip to content

Forwarding ref returns "uninitialized" element #2005

@xehpuk

Description

@xehpuk

Describe the bug

I have this component:

function Div(props) {
    return (
        <div {...props}/>
    )
}

And I use it like this:

<Div id="hello" ref={el => console.log('id', el.id)}>Div</Div>

Your Example Website or App

https://stackblitz.com/edit/solidjs-templates-edibnb?file=src%2FApp.jsx

Steps to Reproduce the Bug or Issue

Use the Div component and look at the console output. It shows:

id <empty string>

Expected behavior

I expected to have access to the element's attributes, e.g. id. Instead, I seem to get default attributes ("" instead of "hello").

Screenshots or Videos

No response

Platform

  • OS: Windows
  • Browser: Firefox
  • Version: 120.0.1

Additional context

Workaround: Wrap the ref inside onMount().

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions