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

10,086

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.

Share:
10,086

Related videos on Youtube

user2878848
Author by

user2878848

Updated on June 04, 2022

Comments

  • user2878848
    user2878848 almost 2 years

    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({});
    };