@logux/state
Version:
A tiny (152 bytes) state manager for React/Preact/Vue/Svelte with many atomic tree-shakable stores
20 lines (18 loc) • 503 B
TypeScript
import { MapStore } from '../create-map/index.js'
/**
* Keep key-value data in localStorage.
*
* ```js
* import { createPersistent } from '@logux/state'
*
* export const settings = createPersistent<{
* theme: 'dark' | 'light'
* favorite: string
* }>({ theme: 'light' }, 'settings:')
* ```
*
* @param prefix Optional key prefix in localStorage.
*/
export function createPersistent<
Value extends Record<string, string | undefined>
>(initial?: Value, prefix?: string): MapStore<Value>