Proposal for standardising getWrappedInstance methods on wrappers #437
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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) andwithStyles
(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 :)