-
-
Notifications
You must be signed in to change notification settings - Fork 765
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
Usage of useTranslation hook inside components cause rerender #654
Comments
Hi @srgvrnv - thanks for this report. Do you mind quickly setting up a demo repo that we can reproduce this and track down the issue? |
Hi! |
@isaachinman Hello! Any updates on this issue? |
@srgvrnv I don't really know what you expect, you're rendering 1100 components in a loop. |
Size of loop is ridiculously huge just to demonstrate a problem. I face this issue while rendering nested set of 50 entities with nesting level of 2 using of Anyway react-i18next have no issue to render "1100 components in a loop" while next-i18next have some problems with it Maybe there is some misunderstanding but I expect it to work same way Am I missing something here? |
I'm having the same issue. @srgvrnv were you able to understand what the issue was? Best, |
@ricardobrandao Unfortunately not. For now I solve it with using static class which I setup in LocaleHandler.locale = language;
LocaleHandler.t = t; |
Don't have a lot of spare time at the moment, but very happy to hear any suggestions/ideas. |
Is it possible to use |
@SalahAdDin Of course. |
This comment has been minimized.
This comment has been minimized.
I found out whenever the language is changed, the router would be replaced which is causing the extra rerendering (source code). Probably this is the expected behavior, since next.js also handles the routing part but @srgvrnv you said you fixed this issue by setting static values, but are you still using |
I have the same issue and whydidyourender library point it out very well. |
Same issue pointed by whydidyourender, when you use the hook across your app and realize most re-render are caused by the |
Does anyone mind testing this issue in |
I don't know why but I got the same issue with react-i18next. LOL |
@isaachinman upgrading to v8.0.0 from v6 is really painful. would there be any patch for the v6 to fix this issue? |
@k4mr4n As with all previous releases, I won't be actively working on maintenance, but if users want to open PRs, I will certainly review, merge, and publish them. |
For anyone interested, re-render is still happening to me (probably should at some point), but I ended up using |
@andrei-scripcaru why did you switched to |
Switching the language was causing children (not sure exactly which ones) to re-render and there's no re-rendering with |
|
@SalahAdDin What was the intention of the @? If anyone can provide reproducible examples of faulty behaviour, issues will be fixed quickly. |
any solution ? |
Create a file Translate.js function Translate(props) { then add this function in the component |
There is this effect in source code causing useTranslation to refresh the "t" function
|
Guys ... could it be your bug ??? (this was my one) Try disabling React.StrictMode !!!! ;) |
@Poyoman39 That is not |
I know this is a pretty old thread, but I've found that |
Only i18n - and we have 2 renders. Why? https://codesandbox.io/s/i18next-10-rerender-not-fixed-4eydfm?file=/src/App.js |
The problem persists: https://codesandbox.io/s/heuristic-agnesi-9t91nh I now React's StrictMode will cause a double render, but if we divide the Children's render by 2, we'll still have a render. |
Describe the bug
When I use useTranslation hook inside function component it causes multiple rerenders. Can't reproduce it with create-react-app and react-i18next. So it should be landed here. If I use react profiler I see that it takes 1102 render, but with create-react-app and react-i18next it takes only 2. Am I missing something or this is a bug?
Occurs in next-i18next version
4.2.1
Steps to reproduce
Expected behaviour
Shouldn't be rendered so much times
OS (please complete the following information)
The text was updated successfully, but these errors were encountered: