I'm looking for a way to get translation text without using FormattedMessage. Until now, I've found only this solution that provides to use ContextTypes an React's EXPERIMENTAL feature. Are there others ways to accomplish this (or other library/npm module)?
Asked
Active
Viewed 494 times
1 Answers
3
I prefer using context
, but react-intl does also provide a higher order component injectIntl
you can use instead. This will pass a prop intl
that has all the imperative formatting functions.
import React from "react";
import {injectIntl, intlShape} from "react-intl";
class MyComponent extends React.Component {
static propTypes = {
intl: intlShape.isRequired
}
render() {
return <p>{this.props.intl.formatDate(new Date())}</p>;
}
}
export default injectIntl(Component);

Aaron Beall
- 49,769
- 26
- 85
- 103
-
I would prefer using context's solution, but it is an experimental feature that could change at any time. Do you know other library like react-intl? – Webman May 24 '16 at 21:36
-
@Webman I'm not sure you understood my answer, I updated it to clarify: you can use react-intl's `injectIntl` function *instead* of `context`. This is provided by react-intl. – Aaron Beall May 24 '16 at 21:50