1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-11-10 01:19:53 +01:00
unleash.unleash/frontend/src/hooks/useLocationSettings.ts
Gastón Fournier abe160eb7d
feat: Unleash v7 ESM migration (#9877)
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>
2025-05-14 09:47:12 +02:00

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(),
);