goobs-frontend
Version:
A comprehensive React-based libary for building modern web applications
32 lines • 1.48 kB
TypeScript
/**
* Adapter for fields whose UI value type `T` differs from the value stored in
* the form engine (e.g. a DateField surfaces `Date | null` but the schema /
* store may keep an ISO string). `valueFromStore` maps store→UI on read;
* `payloadToStore` maps UI→store on change.
*/
export interface FieldBindingAdapter<T> {
valueFromStore: (stored: unknown) => T;
payloadToStore: (payload: T) => unknown;
}
export interface UseFieldBindingArgs<T> {
/** The field name. When absent, the field is never auto-bound. */
name?: string | undefined;
/**
* The caller's explicit value. When defined, the field is controlled by the
* caller and this hook is a pass-through (back-compat path).
*/
value?: T | undefined;
/** The caller's explicit onChange (preserved and chained after binding). */
onChange?: ((next: T) => void) | undefined;
/** The caller's explicit onBlur (preserved and chained after binding). */
onBlur?: (() => void) | undefined;
/** Optional store⇄UI value adapter. */
adapter?: FieldBindingAdapter<T> | undefined;
}
export interface UseFieldBindingResult<T> {
value?: T | undefined;
onChange?: ((next: T) => void) | undefined;
onBlur?: (() => void) | undefined;
}
export declare function useFieldBinding<T>({ name, value, onChange: originalOnChange, onBlur: originalOnBlur, adapter, }: UseFieldBindingArgs<T>): UseFieldBindingResult<T>;
//# sourceMappingURL=useFieldBinding.d.ts.map