reactjsi18nextreact-i18next

Difference between useTranslation and direct import from i18next


Is there any practical difference between importing the useTranslation hook, then getting the t() function from it:

import { useTranslation } from 'react-i18next';

// Inside a component:
const { t } = useTranslation();

and importing the t() function directly from i18next:

import { t } from 'i18next';

Solution

  • Yes, there is a practical difference between these two approaches:

    1. useTranslation() from react-i18next:

    import { useTranslation } from 'react-i18next';
    
    const { t } = useTranslation();
    

    2. Direct import from i18next:

    import { t } from 'i18next';
    

    In summary: