@guruhotel/aura-hooks
Version:
🪝 Hooks library designed by the Guruhotel team for Aura UI
16 lines (15 loc) • 878 B
TypeScript
export declare type StorageType = "localStorage" | "sessionStorage";
export interface IStorageProperties<T> {
/** Storage key */
key: string;
/** Default value that will be set if value is not found in storage */
defaultValue?: T;
/** If set to true, value will be update is useEffect after mount */
getInitialValueInEffect?: boolean;
/** Function to serialize value into string to be save in storage */
serialize?(value: T): string;
/** Function to deserialize string value from storage to value */
deserialize?(value: string): T;
}
export declare function useLocalStorage<T = string>(props: IStorageProperties<T>): readonly [T | undefined, (val: T | ((prevState: T) => T)) => void];
export declare function useSessionStorage<T = string>(props: IStorageProperties<T>): readonly [T | undefined, (val: T | ((prevState: T) => T)) => void];