UNPKG

@stimulus-library/mixins

Version:

A library of useful controllers for Stimulus

22 lines (21 loc) 756 B
import { Controller } from "@hotwired/stimulus"; export type Serializer<T> = { deserialize(raw: string): T; serialize(value: T): string; isEmpty(value: T): boolean; }; export interface LocalStorageProxy<T> { get value(): T; set value(value: T); read(): T; write(value: T): void; clear(): void; isEmpty(): boolean; } export declare const StorageSerializers: Record<"boolean" | "object" | "number" | "any" | "string" | "map" | "set", Serializer<any>> & { [idx: string]: Serializer<any>; }; export declare function useLocalStorage<T>(controller: Controller, key: string, defaultValue?: any, opts?: { onChange?: ((newValue: any, oldValue: any) => void) | null; writeDefaults?: boolean; }): LocalStorageProxy<T>;