UNPKG

@tanstack/react-persister

Version:

Utilities for persisting state to local storage, session storage, indexedDB, and more.

20 lines (19 loc) 1.1 kB
import { StoragePersisterOptions } from '@tanstack/persister/storage-persister'; /** * A hook that persists state to localStorage and syncs it across tabs * * @example * ```tsx * const [value, setValue] = useLocalStorageState('my-key', 'initial value') * ``` */ export declare function useLocalStorageState<TValue, TSelected extends Partial<TValue> = TValue>(key: string, initialValue: TValue, options?: Omit<StoragePersisterOptions<TValue, TSelected>, 'key' | 'storage'>): readonly [TValue | TSelected, import('react').Dispatch<import('react').SetStateAction<TValue | TSelected>>]; /** * A hook that persists state to sessionStorage and syncs it across tabs * * @example * ```tsx * const [value, setValue] = useSessionStorageState('my-key', 'initial value') * ``` */ export declare function useSessionStorageState<TValue, TSelected extends Partial<TValue> = TValue>(key: string, initialValue: TValue, options?: Omit<StoragePersisterOptions<TValue, TSelected>, 'key' | 'storage'>): readonly [TValue | TSelected, import('react').Dispatch<import('react').SetStateAction<TValue | TSelected>>];