Added useLocale hook.

This commit is contained in:
Mike Cao 2020-09-08 20:46:31 -07:00
parent 7e26c9571e
commit 52acb691ad
5 changed files with 24 additions and 14 deletions

View file

@ -1,23 +1,22 @@
import React, { useEffect } from 'react';
import { IntlProvider } from 'react-intl';
import { Provider, useDispatch, useSelector } from 'react-redux';
import { Provider } from 'react-redux';
import { useStore } from 'redux/store';
import { updateApp } from 'redux/actions/app';
import useLocale from 'hooks/useLocale';
import { messages } from 'lib/lang';
import 'styles/variables.css';
import 'styles/bootstrap-grid.css';
import 'styles/index.css';
const Intl = ({ children }) => {
const dispatch = useDispatch();
const locale = useSelector(state => state.app.locale);
const [locale, setLocale] = useLocale();
const Wrapper = ({ children }) => <span className={locale}>{children}</span>;
useEffect(() => {
const saved = localStorage.getItem('locale');
if (saved) {
dispatch(updateApp({ locale: saved }));
setLocale(saved);
}
});