prometheus/web/ui/mantine-ui/src/state/initializeFromLocalStorage.ts
Julius Volz 70221fc4a0 Build initial targets page
Signed-off-by: Julius Volz <julius.volz@gmail.com>
2024-04-03 14:43:03 +02:00

15 lines
425 B
TypeScript

// This has to live in its own file since including it from
// localStorageMiddleware.ts causes startup issues, as the
// listener setup there accesses an action creator before Redux
// has been initialized.
export const initializeFromLocalStorage = <T>(
key: string,
defaultValue: T
): T => {
const value = localStorage.getItem(key);
if (value === null) {
return defaultValue;
}
return JSON.parse(value);
};