Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Custom ref prop type needs work #29

Open
juanca opened this issue Jul 16, 2018 · 4 comments
Open

Custom ref prop type needs work #29

juanca opened this issue Jul 16, 2018 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@juanca
Copy link
Owner

juanca commented Jul 16, 2018

604c752

@ahuth
Copy link
Collaborator

ahuth commented Mar 7, 2019

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.

@juanca
Copy link
Owner Author

juanca commented Mar 12, 2019

Interesting. We would like to support server-side rendering as well. I wonder if we can shim Element in a server environment.

@juanca juanca added enhancement New feature or request good first issue Good for newcomers labels Jun 9, 2019
@juanca
Copy link
Owner Author

juanca commented Jul 4, 2019

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.

@ahuth
Copy link
Collaborator

ahuth commented Jul 5, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants