import { AtomOptions, RecoilState } from 'recoil'; interface IRPersistOptions { /** * (Optional) Key to use in storage. Defaults to the atom's key. */ storageKey?: string; /** * (Optional) Type of storage to use. Defaults to `localStorage`. */ storage?: Storage; /** * (Optional) A function which accepts a data object retrieved from storage and returns whether it should be loaded as the state (is valid) * * @example * (data: object) => { * // will not load if falsy * if (!data) return false * // will not load if items property non-existant or not array * if (!data.items || !Array.isArray(data.items)) return false * // will not load if data.items contains non-string items * if (data.item.filter(d => typeof d !== 'string').length > 0) return false * * return true * } */ validator?: (data: T) => boolean; } /** * A wrapper around Recoil's `atom` to automate LocalStorage persistence. * * Accepts all the normal atom options, then the key to use for local storage on top of that. * * Stores the state in LocalStorage using `JSON.stringify`. **Please ensure that * the state returned is valid as this can be edited by users in DevTools.** * * @param atomOptions The options supplied to Recoil's `atom()` * @param persistOptions (Optional) The options used for persistence * * @example Persist using default options * * // Persists under 'myState' key in LocalStorage * persistentAtom({ * key: 'myState', * default: { data: null }, * }) * * @example Persist in SessionStorage * * // Persists under 'my-state' key in SessionStorage * persistentAtom( * { * key: 'myState', * default: { data: null }, * }, * { * storageKey: 'my-state', * storage: window.sessionStorage, * }, * ) */ export declare function persistentAtom(atomOptions: AtomOptions, persistOptions?: IRPersistOptions): RecoilState; export {};