react-state-sync
Version:
A custom React hook for synchronized state
18 lines (17 loc) • 712 B
TypeScript
interface SyncStateOptions<ValueType> {
defaultValue: ValueType;
key?: string;
storage?: Storage | false;
serialize?: (value: ValueType) => string;
deserialize?: (stringValue: string | null) => ValueType | null;
onInit?: (value: ValueType) => void;
onUpdate?: (value: ValueType) => void;
}
export declare function createSyncState<ValueType>({ defaultValue, key, storage, serialize, deserialize, onInit, onUpdate, }: SyncStateOptions<ValueType>): {
useSyncValue: {
(): ValueType;
<MappedType>(mapper: (originalValue: ValueType) => MappedType): MappedType;
};
setSyncValue: (newValue: ValueType | ((oldValue: ValueType) => ValueType)) => void;
};
export {};