-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
Wanted: blessed access _owner #2123
Comments
Are you asking for the parent or the owner? In the case of passing components around, these are different. Consider:
C's owner is A but it's mounted into a div (and that div's "parent" is B, I suppose). Concrete use cases would be helpful. (It doesn't look like there are any uses of _owner in react-router right now?) |
The thing I'd like access to is owner. I can always get the parent element using a combination of We don't currently use My use case is this:
On the server (rendering components server-side) we may have many URLs at once because a server processes multiple requests concurrently. Thus, keeping "active" state in a store doesn't work. The solution I'm using in the active-routes branch is to keep active state in the |
Sounds like the parent hierarchy would work just as well for this – the Routes component will still be at the top. This is probably best solved by contexts (still undocumented; currently owner-based but soon parent-based per #2112). It may also be worth encouraging the use of https://github.com/brianmcd/contextify for server rendering so that the execution environments are completely isolated (that's what react-page does). |
Does the parent tree give me access to the component instance? Or just the DOM node? |
I wasn't proposing any particular API, but it could give access to the instance. |
In that case, yes. That could work. Does React put any properties on the context by default? Or is it derived solely from an object the user provides to a descriptor? Edit: Just wondering how I might use |
The idea is you could have the Routes component return in its getChildContext method whatever info the Link needs and then the Link could access this.context.routeInfo.blah or whatever. This commit message and tests gives a general idea of the API: (withContext is probably going away, use getChildContext instead.) |
@spicyj Thank you very much. Contexts work beautifully for my use case. Closing! 🎉 |
Over in the react-router project we would really, really like a "blessed" way to access the component that was on the bottom of the render stack at the time another was rendered.
ReactCompositeComponent
s currently have a reference to their "owner" component usingthis._owner
, but it looks like it's going to be removed.I'm currently trying to understand the reasons for wanting to get rid of
_owner
so that we can find a way to satisfy those concerns but still preserve access to a component's owner in some way.There are lots of places in the DOM API where you can go back up the tree, including
parentNode
,ownerDocument
,parent
, andownerNode
. Being able to essentially do the same thing in React's component API would be incredibly useful.The text was updated successfully, but these errors were encountered: