-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
See #1190 for context
TL;DR
You cannot locate a DOM node for a functional component. We allow users to pass components and elements into our components. We then sometimes try to locate the DOM node of those passed in components. This results in an error if the user passed a stateless functional component as there is no DOM node.
The solution, create a wrapper class and HOC that locates its own DOM node but renders the child or wrapped component in place.
Progress to date
OK ugly code here, but, I've dug up the experiment I did for this here: http://www.react.run/HJa1BVYQl/24
This would need to be adapted to also work as a HOC rather than only on a child element:
const RefsNotSupported = () = <p>I'm a functional component</p>
<RefsNotSupported ref={node => console.log(node)} />
// => null
const RefsSupported = Ref(RefsNotSupported)
<RefsSupported ref={node => console.log(node)} />
// => <p>I'm a functional component</p>
Finally, this component and HOC would need to be implemented everywhere we use a trigger
and or ref
. It would also need to be applied in src/lib/getElementType
, which powers the as
prop, so that all as
components can use ref
s.
If anyone would like to pick this up, that would beyond amazing 👍