2020-09-09 05:46:31 +02:00
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2020-09-20 10:33:39 +02:00
|
|
|
import { setLocale } from 'redux/actions/app';
|
2020-09-19 19:35:05 +02:00
|
|
|
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();
|
|
|
|
|
2020-09-20 10:33:39 +02:00
|
|
|
function saveLocale(value) {
|
2020-09-19 19:35:05 +02:00
|
|
|
setItem(LOCALE_CONFIG, value);
|
2020-09-20 10:33:39 +02:00
|
|
|
dispatch(setLocale(value));
|
2020-09-09 05:46:31 +02:00
|
|
|
}
|
|
|
|
|
2020-09-20 10:33:39 +02:00
|
|
|
return [locale, saveLocale];
|
2020-09-09 05:46:31 +02:00
|
|
|
}
|