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

how to expose component ref for react-navigation HOC? #22

Open
slorber opened this issue Feb 14, 2018 · 8 comments
Open

how to expose component ref for react-navigation HOC? #22

slorber opened this issue Feb 14, 2018 · 8 comments

Comments

@satya164
Copy link
Member

I think onRef is a nicer API, but maybe getWrappedInstance is a better solution since the community seems to have adopted it already.

Does the HOC need withRef: true config for that

I think it's unnecessary. We just need to check if the component is a function component and not add the ref in that case.

@slorber
Copy link
Member Author

slorber commented Feb 14, 2018

You mean checking for:

const isClassComponent = (Component: Function) => !!Component.prototype.render; ?

And if it's a class, automatically ask for ref?
Does it have any performance cost or any side effect to ask a ref even when client does not need it?

ping @gaearon @markerikson @timdorr @ericf as this solution might be backported in existing HOC libs

@timdorr
Copy link

timdorr commented Feb 14, 2018

We shouldn't create it if we don't need it. It's a wasted effort, especially if you have a large number of connected/HOC'ed components.

@satya164
Copy link
Member

@timdorr can you elaborate? does it have any performance implications? would be great if you could post a link where I can read more.

@timdorr
Copy link

timdorr commented Feb 14, 2018

There's a new API coming for refs that would make the instantiation of the ref explicit, and therefore it's upfront cost as well: https://github.com/reactjs/rfcs/blob/master/text/0017-new-create-ref.md

@satya164
Copy link
Member

satya164 commented Feb 14, 2018

@timdorr it's just a convenience API for the callback ref, right? we are not planning to use that API right now. but what is the cost? memory usage or attaching a ref deopts something?

@timdorr
Copy link

timdorr commented Feb 14, 2018

I don't know specifically. There's no code to go on. But one would assume createRef has some sort of cost associated with it. So, creating that ref and never using it would be a wasted effort. I'm not trying to make it into a big deal, just pointing out the inefficiency (no matter how trivial).

@satya164
Copy link
Member

satya164 commented Mar 7, 2018

https://github.com/bvaughn/rfcs/blob/ref-forwarding/text/0000-ref-forwarding.md

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

3 participants