@kform/react
Version:
React integration for KForm.
26 lines (25 loc) • 1.42 kB
TypeScript
import { Path } from "@kform/core";
import { DistributedOmit } from "../utils/typeUtils";
import { Controller } from "./useController";
import { FormatterOptions } from "./useFormatter";
/** Options available to the {@link useFormattedValue} hook. */
export type FormattedValueOptions<T = unknown, TFormatted = T | undefined> = DistributedOmit<FormatterOptions<T, TFormatted>, "setFormattedValue">;
/**
* Result of the {@link useFormattedValue}: a pair used to read and control the
* form value, containing its formatted representation in the first position of
* the returned pair.
*/
export type FormattedValueResult<T = unknown, TFormatted = T | undefined> = [
formattedValue: TFormatted | undefined,
controller: Controller<T>
];
/**
* Hook facilitating the generation of a formatted value from a value in the
* form manager by providing a way of formatting said value.
*
* @param path Path of the form value to access, relative to the current path.
* @param options Available options.
* @returns A controller used to read and manipulate the form value.
*/
export declare function useFormattedValue<T = unknown>(path?: Path | string, options?: undefined): FormattedValueResult<T, T | undefined>;
export declare function useFormattedValue<T = unknown, TFormatted = T | undefined>(path: Path | string | undefined, options: FormattedValueOptions<T, TFormatted>): FormattedValueResult<T, TFormatted>;