Open juanca opened 6 years ago
Oh man, I've been dealing with this a lot at work. There is an issue about this in facebook/prop-types, and I've been meaning to try writing a custom prop type validator for them.
A lot of people do:
PropTypes.oneOfType([
PropTypes.func, // for legacy refs
PropTypes.shape({ current: PropTypes.instanceOf(Element) })
])
but the instanceOf(Element)
breaks when server-side rendering.
Interesting. We would like to support server-side rendering as well. I wonder if we can shim Element
in a server environment.
I've read some issues on this on other repositories and it seems that we do not need to do any further work.
A "ref" is suppose to be just house a pointer to something. While we traditionally use it for DOM references on a given React Element, it seems like it will be used for any asynchronous value.
I'll leave this issue around for a bit longer but it might not entail any future technical work besides some more concrete research.
Immutable reference to a mutable value.
You're right, assuming Element
is short-sighted. This became more clear for me with hooks, because the useRef
hook is really nice for dealing with callback functions and timeout ids.
https://github.com/juanca/react-aria-components/pull/21/commits/604c752b2c93c45772e8c46ba3568b50b50c8cac