2020-09-19 19:35:05 +02:00
|
|
|
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';
|
2020-09-19 19:35:05 +02:00
|
|
|
|
|
|
|
export default function useTimezone() {
|
2020-10-01 01:27:27 +02:00
|
|
|
const [timezone, setTimezone] = useState(getItem(TIMEZONE_CONFIG) || getTimezone());
|
2020-09-19 19:35:05 +02:00
|
|
|
|
|
|
|
const saveTimezone = useCallback(
|
|
|
|
value => {
|
2020-10-01 01:27:27 +02:00
|
|
|
setItem(TIMEZONE_CONFIG, value);
|
2020-09-19 19:35:05 +02:00
|
|
|
setTimezone(value);
|
|
|
|
},
|
|
|
|
[setTimezone],
|
|
|
|
);
|
|
|
|
|
|
|
|
return [timezone, saveTimezone];
|
|
|
|
}
|