UNPKG

react-storage-complete

Version:

🗄️ React hooks for accessing localStorage and sessionStorage, with syncing and prefix support. The complete package.

23 lines (22 loc) 1.25 kB
import { StorageOptions, StorageState } from './useBrowserStorage'; /** * Access a `sessionStorage` item. Use this in a similar fashion to `React.useState()`. * * See the [documentation](https://justinmahar.github.io/react-storage-complete/?path=/story/hooks-usesessionstorage--docs). * * Examples: * * ```jsx * const [value, setValue] = useSessionStorage('key'); * const [value, setValue] = useSessionStorage('key', 'Default'); * const [value, setValue, initialized, clear, prefixedKey] = useSessionStorage('key', 'Default', { * prefix: 'my-namespace', * }); * ``` * * @param key The key for the stored item. * @param defaultWhenUndefined The default value for the item when it is undefined in `sessionStorage`. * @param options Options for the stored item. See the [documentation](https://justinmahar.github.io/react-storage-complete/?path=/story/hooks-usesessionstorage--docs#props) for more. * @returns The storage state. See the [documentation](https://justinmahar.github.io/react-storage-complete/?path=/story/hooks-usesessionstorage--docs#return) for details. */ export declare function useSessionStorage<T = any>(key: string, defaultWhenUndefined?: T | null | undefined, options?: StorageOptions<T>): StorageState<T>;