UNPKG

1.39 kBTypeScriptView Raw
1import { FieldValues, UseFormStateProps, UseFormStateReturn } from './types';
2/**
3 * This custom hook allows you to subscribe to each form state, and isolate the re-render at the custom hook level. It has its scope in terms of form state subscription, so it would not affect other useFormState and useForm. Using this hook can reduce the re-render impact on large and complex form application.
4 *
5 * @remarks
6 * [API](https://react-hook-form.com/docs/useformstate) • [Demo](https://codesandbox.io/s/useformstate-75xly)
7 *
8 * @param props - include options on specify fields to subscribe. {@link UseFormStateReturn}
9 *
10 * @example
11 * ```tsx
12 * function App() {
13 * const { register, handleSubmit, control } = useForm({
14 * defaultValues: {
15 * firstName: "firstName"
16 * }});
17 * const { dirtyFields } = useFormState({
18 * control
19 * });
20 * const onSubmit = (data) => console.log(data);
21 *
22 * return (
23 * <form onSubmit={handleSubmit(onSubmit)}>
24 * <input {...register("firstName")} placeholder="First Name" />
25 * {dirtyFields.firstName && <p>Field is dirty.</p>}
26 * <input type="submit" />
27 * </form>
28 * );
29 * }
30 * ```
31 */
32declare function useFormState<TFieldValues extends FieldValues = FieldValues>(props?: UseFormStateProps<TFieldValues>): UseFormStateReturn<TFieldValues>;
33export { useFormState };
34//# sourceMappingURL=useFormState.d.ts.map
\No newline at end of file