question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

i18next-react useTranslation with version 22+ requires wrapping t function into <></>

See original GitHub issue

I have a project based on Ant Design and, after upgrading to version 22+ (22.0.4 to be precise), I see the following problem:

image

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:closed
  • Created a year ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
pedrodurekcommented, Oct 29, 2022

Hey @kirill-linnik, it seems message don’t accept null, but t function could return null. I’d advice to fallback to something else. E.g.: t('key') ?? ''

4reactions
badsyntaxcommented, Nov 5, 2022

If you want to make the t function fully type-safe, follow the instructions here https://www.i18next.com/overview/typescript

How can we use the custom types in i18next.d.ts to set the t() function to only return string? this is a pretty major breaking change and i really don’t want to do t('key') ?? '' everywhere.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found