mirror of
https://github.com/Unleash/unleash.git
synced 2025-11-10 01:19:53 +01:00
We're migrating to ESM, which will allow us to import the latest versions of our dependencies. Co-Authored-By: Christopher Kolstad <chriswk@getunleash.io>
30 lines
845 B
TypeScript
30 lines
845 B
TypeScript
import { basePath } from 'utils/formatPath';
|
|
import { createPersistentGlobalStateHook } from './usePersistentGlobalState.js';
|
|
import type React from 'react';
|
|
|
|
export interface ILocationSettings {
|
|
locale: string;
|
|
}
|
|
|
|
interface IUseLocationSettingsOutput {
|
|
locationSettings: ILocationSettings;
|
|
setLocationSettings: React.Dispatch<
|
|
React.SetStateAction<ILocationSettings>
|
|
>;
|
|
}
|
|
|
|
export const useLocationSettings = (): IUseLocationSettingsOutput => {
|
|
const [locationSettings, setLocationSettings] = useGlobalState();
|
|
|
|
return { locationSettings, setLocationSettings };
|
|
};
|
|
|
|
const createInitialValue = (): ILocationSettings => {
|
|
return { locale: navigator.language };
|
|
};
|
|
|
|
const useGlobalState = createPersistentGlobalStateHook<ILocationSettings>(
|
|
`${basePath}:useLocationSettings:v1`,
|
|
createInitialValue(),
|
|
);
|