UNPKG

use-storage-state

Version:

React hook that you can wire with any Storage compatible API like `localStorage`, `sessionStorage`, or a custom one.

21 lines (20 loc) 493 B
class MemoryStorage { constructor() { this.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;