From 15240aa4290753bdce2551df135e6021e9176a1d Mon Sep 17 00:00:00 2001 From: Keith Bauer <15345887+kbauer-hhog@users.noreply.github.com> Date: Thu, 27 Feb 2020 09:02:19 -0500 Subject: [PATCH] Set i18n initial language based on SSR language or static config defaultLanguage to prevent re-renders in multi-lingual apps (#330) --- samples/react/src/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/samples/react/src/index.js b/samples/react/src/index.js index 038de7b4a1..4bf1b4879d 100644 --- a/samples/react/src/index.js +++ b/samples/react/src/index.js @@ -11,6 +11,8 @@ import i18ninit from './i18n'; let renderFunction = ReactDOM.render; +let initLanguage = config.defaultLanguage; + /* SSR Data If we're running in a server-side rendering scenario, @@ -35,6 +37,9 @@ if (__JSS_STATE__) { // when React initializes from a SSR-based initial state, you need to render with `hydrate` instead of `render` renderFunction = ReactDOM.hydrate; + + // set i18n language SSR state language instead of static config default language + initLanguage = __JSS_STATE__.sitecore.context.language; } /* @@ -54,7 +59,7 @@ const graphQLClient = GraphQLClientFactory(config.graphQLEndpoint, false, initia */ // initialize the dictionary, then render the app // note: if not making a multlingual app, the dictionary init can be removed. -i18ninit().then(() => { +i18ninit(initLanguage).then(() => { // HTML element to place the app into const rootElement = document.getElementById('root');