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

Connected Components loose children's refs #67

Closed
ghost opened this issue Nov 20, 2017 · 2 comments
Closed

Connected Components loose children's refs #67

ghost opened this issue Nov 20, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented Nov 20, 2017

Once a component is enhanced with kea it it's refs are gone.
Therefore this.props.children.ref is an empty object from the parent.

<Parent >
    <Child />
</Parent>

Neither facebook/react#8873
nor https://reactjs.org/docs/refs-and-the-dom.html#exposing-dom-refs-to-parent-components
works here.

@ghost ghost changed the title Connected Components loose childre's refs Connected Components loose children's refs Nov 20, 2017
@mariusandra
Copy link
Member

Hey, it's hard to answer your question without knowing exactly what it is that you're trying to do :).

Could you provide a more complete example that doesn't work? Here's a webpackbin you can play around with.

In any case, Kea delegates its "magic" to react-redux's connectAdvanced function, which in turn wraps the <Child /> inside <Connect><Child /></Connect>.

If you wrap everything with a <Parent>...</Parent> and really need to get the refs from within Child in Parent, it should be possible with callback refs, as described here.

The alternative is to extend kea and send { withRef: true } to connectAdvanced and then call this.refToChild.getWrappedInstance().refs from within Parent to get the Child's refs, as described here, however this increases complexity in the library and I'd prefer to not have to maintain this in the future. Callback refs should do the trick just fine.

@mariusandra
Copy link
Member

closing due to inactivity

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

1 participant