use-storage-state
Version:
React hook that you can wire with any Storage compatible API like `localStorage`, `sessionStorage`, or a custom one.
19 lines (18 loc) • 463 B
JavaScript
class MemoryStorage {
#storage = new Map();
getItem(key) {
if (this.#storage.has(key)) {
const value = this.#storage.get(key);
return value === undefined ? "undefined" : value;
}
return null;
}
setItem(key, value) {
this.#storage.set(key, value);
}
removeItem(key) {
this.#storage.delete(key);
}
}
const memoryStorage = new MemoryStorage();
export default memoryStorage;