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

Ability to call formatting API without wrapping a component with InjectIntl() in class components #1609

Closed
mtcanada opened this issue Mar 27, 2020 · 4 comments
Labels

Comments

@mtcanada
Copy link

mtcanada commented Mar 27, 2020

Is your feature request related to a problem? Please describe.
Our project is fairly huge and already contains wrapped components by one another so we really do not want to use InjectIntl() to wrap class components to use formatting API (it also breaks some tests as well).

Describe the solution you'd like
It would be great if we could just import intl from 'react-intl' and "intl.API" to call the API ( like intl.formatMessage)
OR
Is there any way to call Formatting API without using InjectIntl() for class components? possibly with createIntl()?

Describe alternatives you've considered
At least simpler and less complicated way to use formatting API in class components

Additional context
This complexity of InjectIntl() makes it very to use React Intl in a big project. We are about to use other libraries just because we do not want to use InjectIntl(), but the rest of the library and related babel-plugins are very good so if possible I would like to keep using React-Intl.

@longlho
Copy link
Member

longlho commented Mar 27, 2020

you can use our React hook useIntl as well.

@mtcanada
Copy link
Author

you can use our React hook useIntl as well.

I believe useIntl is only for functional component.

@longlho
Copy link
Member

longlho commented Mar 27, 2020

We do export IntlContext so technically you can get the Consumer out of that. Would that work for you?

The intl object from react-intl is a cached instance of several thing, including locale so it's not something we can export out statically. That falls on the user land.

@stale
Copy link

stale bot commented Jun 20, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 20, 2020
@stale stale bot closed this as completed Jun 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants