22 lines
470 B
TypeScript
22 lines
470 B
TypeScript
const getData = (key: string): unknown | undefined => {
|
|
try {
|
|
const data = localStorage.getItem(key);
|
|
|
|
if (data) {
|
|
return JSON.parse(data);
|
|
}
|
|
} catch (error) {
|
|
console.error('Read from local storage', error);
|
|
}
|
|
};
|
|
|
|
const setData = (key: string, value: unknown): void => {
|
|
try {
|
|
localStorage.setItem(key, JSON.stringify(value));
|
|
} catch (error) {
|
|
console.error('Save in local storage', error);
|
|
}
|
|
};
|
|
|
|
export { getData, setData };
|