react-storage-complete
Version:
🗄️ React hooks for accessing localStorage and sessionStorage, with syncing and prefix support. The complete package.
23 lines (22 loc) • 1.23 kB
TypeScript
import { StorageOptions, StorageState } from './useBrowserStorage';
/**
* Access a `localStorage` item. Use this in a similar fashion to `React.useState()`.
*
* See the [documentation](https://justinmahar.github.io/react-storage-complete/?path=/story/hooks-uselocalstorage--docs).
*
* Examples:
*
* ```jsx
* const [value, setValue] = useLocalStorage('key');
* const [value, setValue] = useLocalStorage('key', 'Default');
* const [value, setValue, initialized, clear, prefixedKey] = useLocalStorage('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 `localStorage`.
* @param options Options for the stored item. See the [documentation](https://justinmahar.github.io/react-storage-complete/?path=/story/hooks-uselocalstorage--docs#props) for more.
* @returns The storage state. See the [documentation](https://justinmahar.github.io/react-storage-complete/?path=/story/hooks-uselocalstorage--docs#return) for details.
*/
export declare function useLocalStorage<T = any>(key: string, defaultWhenUndefined?: T | null | undefined, options?: StorageOptions<T>): StorageState<T>;