Conversation
The `TranslationContext` instance is required so a component can be flagged with the correct `static contextType = TranslationContext` value. Without setting that (at least in React 16.7), the `this.context` value is fully undefined and the component is not actually tied to the context. By exporting it, consumer can simply set the context type and everything works out of the box.
|
I'm not sure I understand, why don't you use the |
|
So, I was following along https://marmelab.com/react-admin/Translation.html (Translating Your Own Components) which states that However, I wasn't able to make it work with: I had to do this instead to make it work: Don't hesitate to point to some misconceptions about this usage. |
|
@maoueh You should read the whole section, it also specifies that you should use the |
|
I read everything, and using the HOC works great, I wanted to test out Is the Even after using Simply tells me you would prefer between ditching it or supporting it. |
|
I'd rather have only one way to do something so I would recommend ditching the context documentation. Ping @fzaninotto |
|
I agree, we should remove the part about the context in the documentation. Using the translate HOC, we can abstract the actual implementation (and it will make it easier to transition to React hooks in the near future). @maoueh Would you be willing to do a PR on the documentation for that? |
|
Replaced by #2841 |
The
TranslationContextinstance is required so a component can be flagged with the correctstatic contextType = TranslationContextvalue. Without setting that (at least in React 16.7), thethis.contextvalue is fully undefined and the component is not actually tied to the context.By exporting it, consumer can simply set the context type to the value of
import { TranslationContext } fromreact-admin` and everything works out of the box.