Key Value Store
A service that persists key/value pairs to disk. Can be used standalone or for Redux Persist.
↓ Import the KV serviceimport {KV} from 'react-exo/kv';
↓ Create or get a versioned storeconst kv = KV.init('exo', 1.0);
↓ Set a value to a keyawait kv.setItem('foo', 'bar');
↓ Get a value from a keyconst value = await kv.getItem('foo');
↓ Remove a key/value pairawait kv.removeItem('foo');
↓ Clear the entire storeawait kv.clear();
Advanced Usage
↓ Working with booleansawait kv.setItem('verified', false);const const verified: boolean | undefinedverified = await kv.getItem('verified', Boolean);
↓ Working with numbersawait kv.setItem('age', 18);const const age: number | undefinedage = await kv.getItem('age', Number);
↓ Working with byte arraysconst data = new Uint8Array([0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x2C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00]);await kv.setItem('photo', data.buffer);
const const photo: ArrayBuffer | undefinedphoto = await kv.getItem('photo', ArrayBuffer);
↓ Working with default valuesconst language = await kv.getItem('language', 'en-US');const showLogo = await kv.getItem('showLogo', true);
const fontSize = await kv.getItem('fontSize', 16);
Dependencies
Technology
Platform | Library | Support | Notes |
---|---|---|---|
Web | IDB-KV | ✅ | Sync methods use local storage |
Native | MMKV | ✅ | - |