Skip to content

Commit

Permalink
Merge pull request #21 from Zurdge/main
Browse files Browse the repository at this point in the history
Fix i18n and Storybook Play interactions
  • Loading branch information
stevensacks committed Jun 6, 2023
2 parents 2f5c930 + c9195c3 commit 696ad25
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions src/withI18Next.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,18 @@ export const withI18Next = (
} = context;

const [{locale}] = useGlobals();
const [show, setShow] = useState(true);
const timeoutRef = useRef(null);

useEffect(() => {
if (locale) {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
setShow(false);
i18n?.changeLanguage(locale);
timeoutRef.current = setTimeout(() => setShow(true), 100);
return () => {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
};
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [locale]);

if (i18n && show) {
return (
<Fragment key={locale}>
<I18nextProvider i18n={i18n}>
{story(context) as ReactNode | null}
</I18nextProvider>
</Fragment>
);
}
return story(context);
return (
<>
<I18nextProvider i18n={i18n}>
{story(context) as ReactNode | null}
</I18nextProvider>
</>
);
};

0 comments on commit 696ad25

Please sign in to comment.