Skip to content

Commit

Permalink
fix: useLayoutEffect will be warning in ssr mode (#533)
Browse files Browse the repository at this point in the history
* fix: useLayoutEffect will be warning in ssr mode

* format the code
  • Loading branch information
moecasts committed Feb 20, 2021
1 parent d931276 commit 2b2c169
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/plugin-locale/src/templates/locale.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ export function _onCreate() {
setIntl(locale);
}

const useIsomorphicLayoutEffect =
typeof window !== 'undefined' &&
typeof window.document !== 'undefined' &&
typeof window.document.createElement !== 'undefined'
? React.useLayoutEffect
: React.useEffect

export const _LocaleContainer = (props:any) => {
const [locale, setLocale] = React.useState(() => getLocale());
const [intl, setContainerIntl] = React.useState(() => getIntl(locale, true));
Expand All @@ -41,7 +48,7 @@ export const _LocaleContainer = (props:any) => {
setContainerIntl(getIntl(locale));
};

React.useLayoutEffect(() => {
useIsomorphicLayoutEffect(() => {
event.on(LANG_CHANGE_EVENT, handleLangChange);
{{#Title}}
// avoid reset route title
Expand Down

0 comments on commit 2b2c169

Please sign in to comment.