-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useTranslation is the cause of the rerender component #1291
Comments
Same issue with next-i18next |
check the code of useTranslation -> it sets that function initially and on languageChange (and optionally by userland code binded events) -> so that function only changes if something is "bad" in userland code - not by design |
@jamuhl Thanks for your reply. I've already checked it with the non-Gatsby project. The useTranslation hook will not cause any re-render issue. I will try to figure out https://codesandbox.io/s/why-did-you-render-sandbox-forked-891xf?file=/src/index.js |
@yash14022001 because we do not expect devs to call changeLanguage over and over again setting the same language... |
🐛 Bug Report
I got rerendering issue while use const { t } = useTranslation() of react-i18next.
In my research, the inside of useTranslation hook used useState to store a getT function. Wrapping getT function inside useCallback hook could not prevent getting this message from WDYR
https://github.com/i18next/react-i18next/blob/master/src/useTranslation.js#L42-L45
https://github.com/i18next/react-i18next/blob/master/src/useTranslation.js#L82
Could you please give me the idea to prevent a re-rendering issue every time use
t
of useTranslation? Thanks 🙇🏻To Reproduce
Repo: https://github.com/zcmgyu/react-i18next-rerender-issue
Expected behavior
Could
useTranslation
feature without re-render because of the same name offixedT
Your Environment
The text was updated successfully, but these errors were encountered: