Skip to content

Commit

Permalink
Set i18n initial language based on SSR language or static config defa…
Browse files Browse the repository at this point in the history
…ultLanguage to prevent re-renders in multi-lingual apps (#330)
  • Loading branch information
kbauer-hhog authored Feb 27, 2020
1 parent 47a8aa5 commit 15240aa
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion samples/react/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

/*
Expand All @@ -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');

Expand Down

0 comments on commit 15240aa

Please sign in to comment.