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

i18n and context in components #102

Closed
tomitrescak opened this issue Feb 26, 2016 · 8 comments
Closed

i18n and context in components #102

tomitrescak opened this issue Feb 26, 2016 · 8 comments

Comments

@tomitrescak
Copy link

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.

@achtan
Copy link
Contributor

achtan commented Feb 26, 2016

read this #44

@tomitrescak
Copy link
Author

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.

@achtan
Copy link
Contributor

achtan commented Feb 26, 2016

ifaik context is passed by mapper to every component (if you dont override it)

@tomitrescak
Copy link
Author

It's not. Only to containers. Components need to be passed context manually.

@arunoda
Copy link
Collaborator

arunoda commented Feb 28, 2016

@tomitrescak you can have a common composer which does that.

@fermuch
Copy link

fermuch commented Feb 29, 2016

is there a problem creating dummy containers just for passing the context to the component?

@tomitrescak
Copy link
Author

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>
   }
}

@arunoda
Copy link
Collaborator

arunoda commented Mar 25, 2016

Closing this and continue the discussion here: #164

@arunoda arunoda closed this as completed Mar 25, 2016
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

4 participants