i18next-react useTranslation with version 22+ requires wrapping t function into <></>
See original GitHub issueI have a project based on Ant Design and, after upgrading to version 22+ (22.0.4 to be precise), I see the following problem:
I can workaround it by wrapping t
function into <></>
, but refactoring whole project because of that is a bit of a pain. I was able to re-construct issue in a playground project in a separate brunch (and you can compare to main
where issue doesn’t exist with a previous version):
https://github.com/kirill-linnik/react-redux/tree/i18next-trouble
checkout, do yarn
- and VSCode shows you error at Main.tsx
line 58. yarn start
does the same,
Issue Analytics
- State:
- Created a year ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
useTranslation (hook) - react-i18next documentation
It gets the t function and i18n instance inside your functional component. ; While most of the time you only need the t...
Read more >Trans Component - react-i18next documentation
e.g. set it to span . By default, text nodes are not wrapped. Can be used to work around a well-known Google Translate...
Read more >TypeScript - react-i18next documentation
In order to fully type the t function, we recursively map all nested keys from your primary locale files or objects. Depending on...
Read more >Testing - react-i18next documentation
In the test, test the myComponent export passing a t function mock: import { MyComponent } from './myComponent';. . <MyComponent t={key => key}...
Read more >withTranslation (HOC) - react-i18next documentation
While you most time only need the t function to translate your content you also ... Use the withTranslation HOC to wrap any...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey @kirill-linnik, it seems message don’t accept
null
, but t function could returnnull
. I’d advice to fallback to something else. E.g.:t('key') ?? ''
How can we use the custom types in
i18next.d.ts
to set thet()
function to only return string? this is a pretty major breaking change and i really don’t want to dot('key') ?? ''
everywhere.