mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
23 lines
530 B
TypeScript
23 lines
530 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) {}
|
|
};
|