Skip to content
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

Wasted renders when the parent component re renders #355

Closed
ahoseinian opened this issue Dec 5, 2017 · 8 comments
Closed

Wasted renders when the parent component re renders #355

ahoseinian opened this issue Dec 5, 2017 · 8 comments

Comments

@ahoseinian
Copy link

Every time parent component re renders the child components that are wrapped with translate HOC are rerendering because the HOC is using Component not PureComponent. Is there a way to prevent this?

@jamuhl
Copy link
Member

jamuhl commented Dec 5, 2017

We once had PureComponents in place - but they did cause the opposite...not rerendering when needed.

Personally we do not use the hoc on every component but pass down the t function via props down to children.

Any improvement would be welcome...but i don't accept a simple replacement of Component with PureComponent.

@ahoseinian
Copy link
Author

What do you think about adding a new option like usePureComponent ?

@jamuhl
Copy link
Member

jamuhl commented Dec 5, 2017

could live with that...

@ahoseinian
Copy link
Author

Cool I will make a PR

@ahoseinian
Copy link
Author

PR #357

@jamuhl
Copy link
Member

jamuhl commented Jan 11, 2018

was merged

@jamuhl jamuhl closed this as completed Jan 11, 2018
@designbyadrian
Copy link

Could someone explain what difference usePureComponent makes? I had an issue where I got tons of re-renders until I passed t down to every child that needed it. Other libraries that use @decorators don't have this issue.

@jamuhl
Copy link
Member

jamuhl commented Mar 27, 2018

You get a reload...when translations changes -> on init when loading a lot of namespaces that or feeding resources manually that rerender could happen a few times -> as state changes multiple times.

you can play with the settings for bindStore, bindI18n (eg. set bindStore to false, bindI18n to languageChanged) https://react.i18next.com/components/translate-hoc.html#a-set-those-on-i18next-init

usePureComponents might also avoid rerenderings...but might have sideeffects in not rerendering when language changes....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants