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

export formatMessage(...) #631

Closed
ralf-strehle opened this issue Sep 1, 2016 · 1 comment
Closed

export formatMessage(...) #631

ralf-strehle opened this issue Sep 1, 2016 · 1 comment

Comments

@ralf-strehle
Copy link

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

ExplainpageFormComp.contextTypes = {
 intl: React.PropTypes.object.isRequired
}

... 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';

@ericf
Copy link
Collaborator

ericf commented Sep 1, 2016

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.

See #416

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants