You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
511 B
24 lines
511 B
4 years ago
|
import localforage from 'localforage';
|
||
4 years ago
|
|
||
|
export async function getStorageItem(key) {
|
||
|
try {
|
||
4 years ago
|
const serializedData = await localforage.getItem(key);
|
||
4 years ago
|
if (serializedData === null) {
|
||
4 years ago
|
return undefined;
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
return JSON.parse(serializedData);
|
||
4 years ago
|
} catch (err) {
|
||
4 years ago
|
return undefined;
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
|
export async function setStorageItem(key, value) {
|
||
|
try {
|
||
4 years ago
|
const serializedData = JSON.stringify(value);
|
||
|
await localforage.setItem(key, serializedData);
|
||
4 years ago
|
} catch (err) {
|
||
4 years ago
|
console.warn(err);
|
||
4 years ago
|
}
|
||
|
}
|