-
Notifications
You must be signed in to change notification settings - Fork 559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stack
does not properly forward ref
#5446
Comments
import React, { forwardRef } from "react"; const Stack = forwardRef((props, ref) => { export default Stack; |
In React, when a ref is passed to a component, that component must forward the ref to a DOM element using React.forwardRef. If the Stack component does not implement forwardRef, the ref will not be attached to the underlying DOM element, resulting in ref.current being null or undefined. import React, { useRef, useEffect } from 'react'; export function Example(props) { useEffect(() => { return <Stack {...props} ref={ref}>contents; |
Primer First Responder, we'd love your help fixing this |
@iansan5653 I believe the types might be too loose for Stack which might be part of the problem here 🤔 The component does not currently support We've been trying to find a good way to do polymorphic For |
Stack
appears to accept aref
prop based on the TypeScript types, but this ref is not actually bound to the underlying element:If
Stack
correctly forwarded its ref, the console would log anHTMLDivElement
instance. However, it instead always logsnull
.The text was updated successfully, but these errors were encountered: