umami/hooks/useLocale.js

17 lines
462 B
JavaScript
Raw Normal View History

2020-09-09 05:46:31 +02:00
import { useDispatch, useSelector } from 'react-redux';
import { updateApp } from 'redux/actions/app';
import { setItem } from 'lib/web';
import { LOCALE_CONFIG } from 'lib/constants';
2020-09-09 05:46:31 +02:00
export default function useLocale() {
const locale = useSelector(state => state.app.locale);
const dispatch = useDispatch();
function setLocale(value) {
setItem(LOCALE_CONFIG, value);
2020-09-09 05:46:31 +02:00
dispatch(updateApp({ locale: value }));
}
return [locale, setLocale];
}