1
0
mirror of https://github.com/kremalicious/umami.git synced 2024-12-22 09:13:37 +01:00
umami/hooks/useTimezone.js
2020-09-30 16:27:27 -07:00

19 lines
494 B
JavaScript

import { useState, useCallback } from 'react';
import { getTimezone } from 'lib/date';
import { getItem, setItem } from 'lib/web';
import { TIMEZONE_CONFIG } from 'lib/constants';
export default function useTimezone() {
const [timezone, setTimezone] = useState(getItem(TIMEZONE_CONFIG) || getTimezone());
const saveTimezone = useCallback(
value => {
setItem(TIMEZONE_CONFIG, value);
setTimezone(value);
},
[setTimezone],
);
return [timezone, saveTimezone];
}