最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there any reason to use useIntl hook in react-intl v3.x? - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 2

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

发布评论

评论列表(0)

  1. 暂无评论