umami/src/components/hooks/useTimezone.ts

21 lines
519 B
TypeScript
Raw Normal View History

import { useState, useCallback } from 'react';
import { getTimezone } from 'lib/date';
2022-08-29 05:20:54 +02:00
import { getItem, setItem } from 'next-basics';
2020-10-01 01:27:27 +02:00
import { TIMEZONE_CONFIG } from 'lib/constants';
2023-05-18 08:20:06 +02:00
export 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];
}
2023-05-18 08:20:06 +02:00
export default useTimezone;