Skip to content

Instantly share code, notes, and snippets.

@javierguzman
Created August 31, 2021 19:55
Show Gist options
  • Save javierguzman/ef7ef7cfa10d0855555901d1bd4e6069 to your computer and use it in GitHub Desktop.
Save javierguzman/ef7ef7cfa10d0855555901d1bd4e6069 to your computer and use it in GitHub Desktop.
Handling i18next cookies depending on whether the user accepts them or not
const LanguageManager: React.FC = ({ children }): JSX.Element => {
const { areCookiesSaved } = useSelector(selectCookiesConsent);
const [languageManagerCurrentInstance, setLanguageManagerCurrentInstance] = useState(
getInitialLanguageManager()
);
useEffect(() => {
if (areCookiesSaved) {
setLanguageManagerCurrentInstance(getLanguageManagerWithCookies());
}
}, [areCookiesSaved]);
return <I18nextProvider i18n={languageManagerCurrentInstance}>{children}</I18nextProvider>;
};
export { LanguageManager };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment