umami/hooks/useTimezone.js

19 lines
494 B
JavaScript
Raw Normal View History

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