-
Notifications
You must be signed in to change notification settings - Fork 47.6k
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
Use parent-context if owner-context is undefined ? #3392
Comments
Unfortunately you're right that there simply is no way to actually use the parent context yet. You're probably best off using the deprecated features until then. Context is a trickier migration because we want it to be I really don't think we should mix the two and conditionally use parent or owner. It's fraught with peril, any dependency change could break everything. #2112 is the issue we're using to track the switch over. @JSFB @sebmarkbage - anything to add? |
There are two tricks you can use in your ChildContextProvider. The simplest one is to just accept a function instead of passing the child in directly: render: function() {
return this.props.createChild();
} So instead of: renderWithContext(<MyComponent />, ...); You would do: renderWithContext(() => <MyComponent />, ...); OR You can use the legacy render: function() {
return React.addons.cloneWithProps(this.props.child);
} This will make the context provider the owner of those children. That way it will work with both parent/owner based context. The complexity comes from the fact that you're passing them in from outside the root. Usually they're created in the root itself. Again, this complexity is why we're changing things. |
Thanks it works fine by passing a function to create the child, and I could remove the withContext call |
…s is a hack for react 0.13 , refer to facebook/react#3392
I'm getting mis-reads (The ReactMount Because my factory component is at the top level, whenever I transition a route it is incrementing the root react-dataid. So for example it will start as Going to explore a little into why but wanted to note here first. |
Ok, I'm avoiding the top level factory pattern for now which works fine. |
Hi,
I'm a library author (https://github.com/stample/atom-react) trying to migrate to 0.13.
I call React.withContext outside of React around a top-level layout component, so it seems I'm in the special case of parent != owner as there is (I guess), no parent for my top-level component.
As
React.withContext
is deprecated, I'm trying to replace it with a top-level wrapper component.This does not work:
To make it work, I have to use:
A weird this is that the following, which is barely the same to me (providing an "owner"?), does not work:
Summary
It seems to me there's a little problem when parent != owner.
withContext
So in any case, I can't get rid of all warnings and I'm forced to keep using a deprecated feature.
And the best case (providing both owner context = parent context) leads to keeping some code like this:
I think maybe if owner context is never used in the whole app, maybe React could use parent context instead of owner context
The text was updated successfully, but these errors were encountered: