You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The format* functions are bound to the intl context, i.e. everything passed to <IntlProvider> and the memoized versions of Intl.NumberFormat, Intl.DateTimeFormat, etc. that are created. If we export these as plain functions instead of methods, then this metadata would need to be passed in each time.
You can see from their definitions that the first two arguments are curried from the intl context.
That said there's a larger task to extract the core of React Intl into a separate package which would allow you create an instance of the intl context and pass it into the <IntlProvider> and this would enable what you're looking for. The lower-level message formatting API is provided as a package: intl-messageformat, but there's more work that formatMessage does on top of this.
Would it make sense to export more API functions like formatMessage(...) ?
Right now the only way I found to use formatMessage(...) inside a React component is to add a contextType with ...
... and then call formatMessage(...) with ...
this.context.intl.formatMessage({id: 'foo.bar'})
But this looks cumbersome to me, it would be easier if we could just write ...
import { formatMessage } from 'react-intl';
The text was updated successfully, but these errors were encountered: