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
Consider Exposing React Components as an Alternate API #23
Comments
@ericf just had this same idea last week! |
Yeah, I had this same thought last week. The declarative form reads much better (when using JSX). In the example you have above, you'd need to also pass a value for the So I think we'll still want this package to also export a mixin that can optionally be used to pipe the i18n metadata through the hierarchy of components via the context. This way you could do something like:
The @sebmarkbage do you think that combo sounds like a good design (mixin being optional, but helps keep things DRY)? |
Yea, you can use context to implicitly thread the locales down. The app just needs to do something like: getChildContext() {
return: { reactIntlLocale: 'en' };
} |
This adds React components for each format type, e.g. `Number`, `Date`, `Message`, et al. These components have been added in a way that's backwards compatible with v1.0.0. The new way to use this package is to reference the new `ReactIntl` global in the browser, or use `var ReactIntl = require('react-intl');` in Node.js. Instead of the Mixin being the default export, the `ReactIntl` module now contains a named export for each component, the mixin, and the function to add locale data. Completely they are: ``` // Component Mixin: ReactIntl.Mixin // Components: (e.g., <Number style="percent">{0.9}</Number>) ReactIntl.Date ReactIntl.Time ReactIntl.Relative ReactIntl.Number ReactIntl.Message // Function to add locale data: ReactIntl.__addLocaleData ``` **Note:** This should be safe to release as `v1.1.0` as all back-compat is maintained. Closes formatjs#23
Make Browserify bundle work in ES3 environments
It would be cool to have format.js React components instead of the mixin. Something like:
That way you don't need the mixin in your component.
Currently this requires an extra wrapper element, but I think we'll be able to get rid of that limitation in React.
The text was updated successfully, but these errors were encountered: