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
Add prop type for Refs #240
Comments
I would also like to see this feature added and would be willing to submit a PR for it if approved. |
PropTypes.shape({ current: PropTypes.instanceOf(Element) }) Breaks under server-side rendering because of Element not existing in that context. ReferenceError: Element is not defined (I agree there should be a prop-type for refs.) |
One thing to note is that refs don't necessarily ref to a DOM element. This became especially clear while learning hooks. It's convenient to use refs to refer to callback functions, timeout ids, the current time, etc, while using Generally I think of refs as being immutable references to mutable values. Of course, maybe those kinds of refs aren't as likely to get passed around as props 🤔 |
That seems less like a ref then, and more like state? |
I have one doubt with:
|
@oliviertassinari no, |
As @ahuth mentioned, we use refs for all sort of non-element things. From the React Docs:
In more than one occasion, whilst migrating class to functional component, I've found some reliance on a mutable value in the class component - and only refs can do this in functional components. So I think instead of:
it should be:
|
How about adding prop types for Refs as a built in feature?
Right now every *ref property looks like this:
Why not just provide it out of the box like:
The text was updated successfully, but these errors were encountered: