Next-i18next: changeLanguage causes re-render

Created on 29 Jan 2020  路  6Comments  路  Source: isaachinman/next-i18next

Hello! I need to translate URL when language is changed. My idea is to replace route with translated one in changeLanguage's callback. The problem is that when language is changed it causes re-render. I want to re-render component when url is translated in order to use it's translated params for api calls. Is there a way to prevent re-render when language is changed?

All 6 comments

Sorry, I don't understand the question. Can you please provide a reproducible example?

I'm using
i18n.changeLanguage(code).then(() => Router.replace(href, as))

I want to change language, after that to replace route with translated url path.
The problem is that both i18n.changeLanguage and Router.replace(href, as) are causing re-render, which calls getInitialProps twice. I want to re-render component only on Router.replace.
How can I prevent re-render on languageChange event.

Pull request #509 seems to do this. I tested it and it works well.

@Accumulative or @denny7 either of you feel like picking up that PR and getting it across the line?

Sure, I can help with that.

509 has been merged.

Was this page helpful?
0 / 5 - 0 ratings