{"action":"opened","issue":{"url":"https://api.github.com/repos/yahoo/react-intl/issues/357","repository_url":"https://api.github.com/repos/yahoo/react-intl","labels_url":"https://api.github.com/repos/yahoo/react-intl/issues/357/labels{/name}","comments_url":"https://api.github.com/repos/yahoo/react-intl/issues/357/comments","events_url":"https://api.github.com/repos/yahoo/react-intl/issues/357/events","html_url":"https://github.com/yahoo/react-intl/issues/357","id":139906428,"number":357,"title":"2.0 suggestion: Use context instead of injectIntl","user":{"login":"MartijnHols","id":4565223,"avatar_url":"https://avatars.githubusercontent.com/u/4565223?v=3","gravatar_id":"","url":"https://api.github.com/users/MartijnHols","html_url":"https://github.com/MartijnHols","followers_url":"https://api.github.com/users/MartijnHols/followers","following_url":"https://api.github.com/users/MartijnHols/following{/other_user}","gists_url":"https://api.github.com/users/MartijnHols/gists{/gist_id}","starred_url":"https://api.github.com/users/MartijnHols/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MartijnHols/subscriptions","organizations_url":"https://api.github.com/users/MartijnHols/orgs","repos_url":"https://api.github.com/users/MartijnHols/repos","events_url":"https://api.github.com/users/MartijnHols/events{/privacy}","received_events_url":"https://api.github.com/users/MartijnHols/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-10T14:40:36Z","updated_at":"2016-03-10T14:40:36Z","closed_at":null,"body":"Hi, I've been playing around with the library for a while (thanks btw! it's awesome!) and my goal has been to try to get it to work without making the code much more complicated. I've gotten to a point where `injectIntl` is the only thing that is bothering me; by wrapping my components, it makes things harder such as using static methods (#196) and testing ([Testing with React Intl](https://github.com/yahoo/react-intl/wiki/Testing-with-React-Intl)); most notably having to use .WrappedComponent (ugh), and conflicting with other libraries such as [rewire](https://github.com/jhnns/rewire).\r\n\r\nHaving also used [react-router](https://github.com/reactjs/react-router) I was wondering why this library doesn't use `context` in the same manner to transfer `intl` to deep components? This is a really easy to use interface intended for this kind of usage.\r\n\r\nI changed the translations example to serve as an example: https://github.com/MartijnHols/react-intl/commit/b6566e270f1e3ff5909d4c5df2c97de3f645ff80. It works just as well and testing becomes much cleaner, users just have to provide a context object with intl assigned to get it to work (which actually makes sense, unlike having to use WrappedComponent and passing the intl property);\r\n\r\n(modified from the last example in [the Wiki](https://github.com/yahoo/react-intl/wiki/Testing-with-React-Intl))\r\n```\r\nconst intlProvider = new IntlProvider({locale: 'en'}, {});\r\nconst {intl} = intlProvider.getChildContext();\r\nconst context = {\r\n    intl: intl\r\n};\r\n...\r\nrenderer.render(<RelativeDate date={date} />, context);\r\n```\r\n\r\nThis completely eliminates the need for `injectIntl`."}}