Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 332x 3332x 3332x 332x 1666x 1666x | import React from "react";
import { StoreDataContext } from "~app/contexts/store-data-context";
import { useMountEffect } from "~app/hooks/use-mount-effect";
import type { StoreValues } from "~app/utils/store-data";
import { LOCALE_STORE_NAME, getLocale } from "~app/utils/store/locale";
import { TIMEZONE_STORE_NAME, getTimezone } from "~app/utils/store/timezone";
const useSetLocalSetting = <T extends keyof StoreValues>(
key: T,
getValue: () => StoreValues[T],
) => {
const [, setValue] = React.use(StoreDataContext)[key];
// oxlint-disable-next-line typescript/no-explicit-any typescript/no-unsafe-argument
useMountEffect(() => setValue(getValue() as any));
};
// Store values that are set to make next render mimic user environment in case of SSR
// (with user tz offset and locale)
export const useStoreLocalSettings = () => {
useSetLocalSetting(LOCALE_STORE_NAME, getLocale);
useSetLocalSetting(TIMEZONE_STORE_NAME, getTimezone);
};
|