admin管理员组文章数量:1391969
We recently updated react-intl from version 2.x to 3.3.2, which meant that we could remove the injectIntl HOC in all files that used any of the format-functions.
Now in v3, we create the intl instance in a separate module and wrap our app in a RawIntlProvider that we provide with this intl object.
Is there any reason to use the useIntl hook provided by react-intl instead of just importing the intl object straight from our created module?
// useIntl hook
const Component = () => {
const intl = useIntl();
intl.formatMessage({});
};
//How we use it atm.
import intl from 'utils/intl';
const Component = () => {
intl.formatMessage({});
};
We recently updated react-intl from version 2.x to 3.3.2, which meant that we could remove the injectIntl HOC in all files that used any of the format-functions.
Now in v3, we create the intl instance in a separate module and wrap our app in a RawIntlProvider that we provide with this intl object.
Is there any reason to use the useIntl hook provided by react-intl instead of just importing the intl object straight from our created module?
// useIntl hook
const Component = () => {
const intl = useIntl();
intl.formatMessage({});
};
//How we use it atm.
import intl from 'utils/intl';
const Component = () => {
intl.formatMessage({});
};
Share
Improve this question
asked Oct 21, 2019 at 10:29
user2878848user2878848
431 gold badge1 silver badge3 bronze badges
1 Answer
Reset to default 2If we read the documentation react-intl, only benefit of using it by importing is when you want to customized the hooks. Otherwise the way you are using it I don't see any problems.
本文标签: javascriptIs there any reason to use useIntl hook in reactintl v3xStack Overflow
版权声明:本文标题:javascript - Is there any reason to use useIntl hook in react-intl v3.x? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744686558a2619737.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论