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

Proposal for standardising getWrappedInstance methods on wrappers #437

Closed
wants to merge 2 commits into from
Closed

Proposal for standardising getWrappedInstance methods on wrappers #437

wants to merge 2 commits into from

Conversation

horyd
Copy link

@horyd horyd commented Jul 15, 2016

I've come into this issue once or twice now, primarily as a result of the amount of component wrappers a given React component can accumulate. Right now I have some with connect (react-redux), injectIntl (react-intl) and withStyles (isomorphic-style-loader) all at once.

So if you have a component that is wrapped three times, and you want to get to the last wrapped instance, you need to do this.refs.component.getWrappedInstance().getWrappedInstance().getWrappedInstance()...

It would be nice for there to be a standard for how you might access wrapped instances where there are multiple levels at play. This concept proposes something like this.refs.yourComponent.getWrappedInstance(3) to do that. I also like the idea of having a means to go all the way down to the last component without necessarily having to specify the amount of layers to unwrap. Just an idea.

I'm posting this here as I think this library has the popularity to set a good standard with how this might be done, which others could follow.

Let me know thoughts :)

@gaearon
Copy link
Contributor

gaearon commented Jul 15, 2016

Hi, thanks for PR! I don’t think we’d want to enforce a convention like this here.

Really, the core issue is that React doesn’t allow forwarding refs.
There is an issue for this, so you can track it here: facebook/react#4213.

@gaearon gaearon closed this Jul 15, 2016
@horyd
Copy link
Author

horyd commented Jul 15, 2016

Ah I see, hadn't come across that before but good to see an ongoing conversation on the topic :) Thanks!

@horyd horyd deleted the unwrap-component branch July 15, 2016 14:31
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

Successfully merging this pull request may close these issues.

2 participants