Skip to content

Key Value Store

A service that persists key/value pairs to disk. Can be used standalone or for Redux Persist.

↓ Import the KV service
import {KV} from 'react-exo/kv';
↓ Create or get a versioned store
const kv = KV.init('exo', 1.0);
↓ Set a value to a key
await kv.setItem('foo', 'bar');
↓ Get a value from a key
const value = await kv.getItem('foo');
↓ Remove a key/value pair
await kv.removeItem('foo');
↓ Clear the entire store
await kv.clear();

Advanced Usage

↓ Working with booleans
await kv.setItem('verified', false);const
const verified: boolean | undefined
verified
= await kv.getItem('verified', Boolean);
↓ Working with numbers
await kv.setItem('age', 18);const
const age: number | undefined
age
= await kv.getItem('age', Number);
↓ Working with byte arrays
const 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 | undefined
photo
= await kv.getItem('photo', ArrayBuffer);
↓ Working with default values
const language = await kv.getItem('language', 'en-US');const showLogo = await kv.getItem('showLogo', true); const fontSize = await kv.getItem('fontSize', 16);

Dependencies

Technology

PlatformLibrarySupportNotes
WebIDB-KVSync methods use local storage
NativeMMKV-