UNPKG

recoil-persist

Version:

Package for recoil to persist and rehydrate store

26 lines (25 loc) 864 B
import { AtomEffect } from 'recoil'; export interface PersistStorage { setItem(key: string, value: string): void | Promise<void>; mergeItem?(key: string, value: string): Promise<void>; getItem(key: string): null | string | Promise<null | string>; } export interface PersistConverter { stringify: (value: any) => string; parse: (value: string) => any; } export interface PersistConfiguration { key?: string; storage?: PersistStorage; converter?: PersistConverter; } /** * Recoil module to persist state to storage * * @param config Optional configuration object * @param config.key Used as key in local storage, defaults to `recoil-persist` * @param config.storage Local storage to use, defaults to `localStorage` */ export declare const recoilPersist: (config?: PersistConfiguration) => { persistAtom: AtomEffect<any>; };