Skip to content

Commit

Permalink
fix: check for i18n to be defined
Browse files Browse the repository at this point in the history
  • Loading branch information
stevensacks committed Jun 13, 2023
1 parent f196acc commit b56feaa
Show file tree
Hide file tree
Showing 3 changed files with 1,466 additions and 1,577 deletions.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@
"build-storybook": "storybook build"
},
"dependencies": {
"storybook-i18n": "^2.0.7"
"storybook-i18n": "^2.0.8"
},
"devDependencies": {
"@storybook/addon-essentials": "^7.0.18",
"@storybook/addon-interactions": "^7.0.18",
"@storybook/addon-links": "^7.0.18",
"@storybook/components": "^7.0.18",
"@storybook/manager-api": "^7.0.18",
"@storybook/preview-api": "^7.0.18",
"@storybook/react": "^7.0.18",
"@storybook/react-vite": "^7.0.18",
"@storybook/react-webpack5": "^7.0.18",
"@storybook/addon-essentials": "^7.0.20",
"@storybook/addon-interactions": "^7.0.20",
"@storybook/addon-links": "^7.0.20",
"@storybook/components": "^7.0.20",
"@storybook/manager-api": "^7.0.20",
"@storybook/preview-api": "^7.0.20",
"@storybook/react": "^7.0.20",
"@storybook/react-vite": "^7.0.20",
"@storybook/react-webpack5": "^7.0.20",
"@storybook/testing-library": "0.1.0",
"@storybook/types": "^7.0.18",
"@storybook/types": "^7.0.20",
"@types/node": "^18.15.0",
"@vitejs/plugin-react": "^3.1.0",
"auto": "^10.46.0",
Expand All @@ -88,7 +88,7 @@
"react-dom": "^18.0.0",
"react-i18next": "^12.3.1",
"rimraf": "^3.0.2",
"storybook": "^7.0.18",
"storybook": "^7.0.20",
"tsup": "^6.6.3",
"typescript": "^4.9.5",
"vite": "^4.3.9",
Expand Down
14 changes: 8 additions & 6 deletions src/withI18Next.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ export const withI18Next = (
parameters: {i18n},
} = context;

const language = i18n.language;
const language = i18n?.language;

const [{locale}] = useGlobals();
const [key, setKey] = useState(0);

useEffect(() => {
i18n.on('languageChanged', () => {
setKey(Date.now());
});
return () => i18n.off('languageChanged');
}, []);
if (i18n) {
i18n.on('languageChanged', () => {
setKey(Date.now());
});
return () => i18n.off('languageChanged');
}
}, [i18n]);

useEffect(() => {
if (i18n && locale && language && locale !== language) {
Expand Down

0 comments on commit b56feaa

Please sign in to comment.