@kinvolk/headlamp-plugin
Version:
The needed infrastructure for building Headlamp plugins.
18 lines (17 loc) • 787 B
TypeScript
/**
* Custom hook to manage state synchronized with localStorage.
* Value must by serializable to JSON.
*
* @template T - The type of the state value.
* @param {string} key - The key under which the state is stored in localStorage.
* @param {T} defaultValue - The default value to use if no value is found in localStorage.
* @returns Returns a tuple containing the current state and a function to update the state.
*
* @example
* const [value, setValue] = useLocalStorageState<string>('myKey', 'default');
* setValue((oldValue) => 'newValue');
*/
export declare function useLocalStorageState<T>(key: string, defaultValue: T): readonly [T, (updater: (old: T) => T) => void];
export declare namespace useLocalStorageState {
var update: (key: string, value: any) => void;
}