-
Notifications
You must be signed in to change notification settings - Fork 51
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
i18n and context in components #102
Comments
read this #44 |
I know about this discussion :/ My problem is that now context has to be inserted into every single component manually via props. Was wondering whether there would be some other way, some way of auto-injecting context to components. But thanks for the pointer. |
ifaik context is passed by mapper to every component (if you dont override it) |
It's not. Only to containers. Components need to be passed context manually. |
@tomitrescak you can have a common composer which does that. |
is there a problem creating dummy containers just for passing the context to the component? |
Thanks for the comments guys. I'm too lazy to do both of these things even though they are probably the cleanest. This is probably not the smartest solution, but I have extended the React.Components class which holds the context as a class property. Now all the components are children of this extended context-enriched component. I'm experimenting with it now and looks ok. Is this a real blasphemy? import Context from "/client/config/context"
class MantraComponent extends React.Component {
constructor() {
base();
this.context = Context;
}
}
class MyComponent extends MantraComponent {
render() {
<div>{ this.context.i18n('key')}</div>
}
} |
Closing this and continue the discussion here: #164 |
I have made i18n library available through context. As a result, I have to pass context to every single component via props. Is this the correct approach you reckon? Or should I just make i18n available through global space? Does not seem clean.
The text was updated successfully, but these errors were encountered: