UNPKG

daily-toolset

Version:

A lightweight, versatile collection of TypeScript utility functions for everyday development needs. Simplify and streamline your Node.js, React, and Next.js projects with a powerful suite of well-organized helpers for strings, arrays, dates, objects, and

17 lines (16 loc) 749 B
/** * useLocalStorage * * A hook to persist state in localStorage. * * @param key The key to use when storing the state in localStorage. * @param initialValue The initial value of the state to be stored. * @param options An object with the following optional properties: * - serialize: A function to serialize the state. Defaults to JSON.stringify. * - deserialize: A function to deserialize the state. Defaults to JSON.parse. * @returns A tuple with the stored value and a function to update the stored value. */ export declare function useLocalStorage<T>(key: string, initialValue: T, options?: { serialize?: (value: T) => string; deserialize?: (value: string) => T; }): readonly [T, (value: T | ((prev: T) => T)) => void];