UNPKG

@alexmarqs/react-use-local-storage

Version:

React hook to persist and sync state with localStorage

17 lines (16 loc) 533 B
import { Dispatch, SetStateAction } from 'react'; /** * useLocalStorage hook options. */ declare type useLocalStorageOptions = { sync: boolean; }; /** * useLocalStorage hook. * @param key - local storage key * @param initialValue - initial value * @param options - hook options * @returns a stateful value and a function to update it */ declare const useLocalStorage: <T>(key: string, initialValue: T, options?: useLocalStorageOptions) => [T, Dispatch<SetStateAction<T>>]; export default useLocalStorage;