@kform/react
Version:
React integration for KForm.
39 lines (38 loc) • 1.62 kB
TypeScript
import { FormManager, Path, SealedFormManagerEvent } from "@kform/core";
/** Options available to the {@link useSubscription} hook. */
export interface SubscriptionOptions {
/**
* Required if no form context is in scope.
*
* If a form context is in scope and this value is also provided, then the
* provided form manager will be used, in which case the current path of the
* form context is ignored.
*/
formManager?: FormManager;
/**
* Function called after the subscription completes, but before any event is
* emitted.
*/
onSubscribe?: () => void | PromiseLike<void>;
/** Function called after unsubscribing. */
onUnsubscribe?: () => void;
/**
* Whether to enable the subscription.
*
* @default true
*/
enabled?: boolean;
}
/**
* Hook that subscribes to all form manager events with paths matching
* {@link path} by running {@link onFormManagerEvent} for each event.
*
* Changes to {@link onFormManagerEvent}, {@link onSubscribe}, or
* {@link onUnsubscribe} do not cause new subscriptions to be performed.
*
* @param path Path of events to subscribe to.
* @param onFormManagerEvent Function called for each event with a path matching
* {@link path}.
* @param subscriptionOptions Available options.
*/
export declare function useSubscription<T = unknown, TChildren = unknown>(path: (Path | string) | undefined, onFormManagerEvent: (event: SealedFormManagerEvent<T, TChildren>) => void | PromiseLike<void>, { formManager: formManagerOption, onSubscribe, onUnsubscribe, enabled, }?: SubscriptionOptions): void;