Skip to content
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

No good reasons to remove string refs from react-native #15559

Closed
jacmkno opened this issue May 2, 2019 · 1 comment
Closed

No good reasons to remove string refs from react-native #15559

jacmkno opened this issue May 2, 2019 · 1 comment

Comments

@jacmkno
Copy link

jacmkno commented May 2, 2019

There are multiple problems with it:

  • It requires that React keeps track of currently rendering component (since it can't guess this). This makes React a bit slower.
  • It doesn't work as most people would expect with the "render callback" pattern (e.g. <DataGrid renderRow={this.renderRow} />) because the ref would get placed on DataGrid for the above reason.
  • It is not composable, i.e. if a library puts a ref on the passed child, the user can't put another ref on it (e.g. Any better way to get refs in ReactTransitionGroup? #8734). Callback refs are perfectly composable.

Originally posted by @gaearon in #8333 (comment)

@jacmkno
Copy link
Author

jacmkno commented May 2, 2019

The reasons that supposedly gave origin to the idea of removing string refs from react native are just not good enough.

It requires that React keeps track of currently rendering component (since it can't guess this). This makes React a bit slower.

They can be implemented at compiler level as a syntactic sugar, or just properly keeping track of things. What exactly makes it so hard to implement this properly? The win here is READABILITY.

It doesn't work as most people would expect with the "render callback" pattern (e.g. ) because the ref would get placed on DataGrid for the above reason.

It would be an obvious mistake if the programmer creates multiple components with the same string ref.

It is not composable, i.e. if a library puts a ref on the passed child, the user can't put another ref on it (e.g. #8734). Callback refs are perfectly composable.

There are many simple ways to solve this issue without losing string refs, possibly accessing the parent component or through contexts.

Just give a try to fix the implementation. Having some issues is no good reason for killing a good a good feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants