Files
openpanel/packages/devtools-ui/src/utils/local-storage.ts
Stefan Pejcic 8496a83edb fork refine
2024-02-05 10:23:04 +01:00

23 lines
572 B
TypeScript

export const getLocalStorage = <T>(name: string, defaultValue: T): T => {
if (typeof window === "undefined") {
return defaultValue;
}
try {
const value = window.localStorage.getItem(name);
return value ? JSON.parse(value) : defaultValue;
} catch (error) {
return defaultValue;
}
};
export const setLocalStorage = <T>(name: string, newValue: T) => {
if (typeof window === "undefined") {
return;
}
try {
window.localStorage.setItem(name, JSON.stringify(newValue));
} catch (error) {}
};