umami/src/components/hooks/useTimezone.ts

21 lines
529 B
TypeScript
Raw Normal View History

import { useState, useCallback } from 'react';
import { getTimezone } from 'lib/date';
2022-08-29 03:20:54 +00:00
import { getItem, setItem } from 'next-basics';
2020-09-30 23:27:27 +00:00
import { TIMEZONE_CONFIG } from 'lib/constants';
2023-05-18 06:20:06 +00:00
export function useTimezone() {
2020-09-30 23:27:27 +00:00
const [timezone, setTimezone] = useState(getItem(TIMEZONE_CONFIG) || getTimezone());
const saveTimezone = useCallback(
2024-01-29 02:33:40 +00:00
(value: string) => {
2020-09-30 23:27:27 +00:00
setItem(TIMEZONE_CONFIG, value);
setTimezone(value);
},
[setTimezone],
);
return [timezone, saveTimezone];
}
2023-05-18 06:20:06 +00:00
export default useTimezone;