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

Automatically passed context property #2507

Closed
tracker1 opened this issue Nov 12, 2014 · 3 comments
Closed

Automatically passed context property #2507

tracker1 opened this issue Nov 12, 2014 · 3 comments

Comments

@tracker1
Copy link

Given that React can and is being used for server-side rendering, and that in a server context stores and dispatchers really need a context-based registry, and that components need to be able to pull context-based instances, not just a global/static instance, it would be extremely useful to be able to specify a global property of React that is a list of properties that are automatically passed from parent to child if not specified.

ex:

//app.js - loads app.jsx
var React = require('React');
React.addInheritingProperty('context');

//app.jsx
render: function() {
    <App context={instance}>
        <Child>will have context for the instance</Child>
    </App>
}

This would apply to rendering of {children} as well as specified controls rendered within a parent. Right now, for example, using Yahoo's fluxible-app you need to explicitely pass context to all children that will use the router and store mixins for the purpose of using stores and the router components.

By making such a functionality available, instance registries for stores/dispatchers would be far easier to utilize. They could simply specify a base property to use (ex _my_store_registry_) and simply use that against rendered instances.

@gaearon
Copy link
Collaborator

gaearon commented Nov 13, 2014

I think this is already being solved by this.context but it's not official yet because of a few issues (e.g. #2112).

@zpao
Copy link
Member

zpao commented Dec 1, 2014

Yea, it sounds like context will fit the bill here. We're in the process of revamping it a bit for more official support.

@zpao zpao closed this as completed Dec 1, 2014
@tracker1
Copy link
Author

tracker1 commented Dec 2, 2014

@gaearon @zpao thanks.. the actual reason for the request is I'm currently using yahoo's flux tooling so I can pre-render server-side and client-side... I noticed I had to pass context from the outer to child nodes in order for child nodes to request a given StoreMixin ...

ex: <SubHeader context={this.props.context}></SubHeader>

It just seemed so wasteful to not have the property automatically propagate... :-) Thanks for letting me know.

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

3 participants