withTranslation (HOC)
What it does
import React from 'react';
import { withTranslation } from 'react-i18next';
function MyComponent({ t, i18n }) {
return <p>{t('my translated text')}</p>
}
export default withTranslation()(MyComponent);import React from 'react';
import { withTranslation } from 'react-i18next';
function MyComponent({ t, i18n }) {
return <p>{t($ => $['my translated text'])}</p>
}
export default withTranslation()(MyComponent);i18n.changeLanguage('en-US');When to use?
withTranslation params
Loading namespaces
Overriding the i18next instance
Not using Suspense
How to
use ref (>= v10.6.0)
hoist non-react statics
use TypeScript with class components
Last updated