You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.2 KiB
64 lines
2.2 KiB
2 years ago
|
import { FieldValues, FormProviderProps, UseFormReturn } from './types';
|
||
|
/**
|
||
|
* This custom hook allows you to access the form context. useFormContext is intended to be used in deeply nested structures, where it would become inconvenient to pass the context as a prop. To be used with {@link FormProvider}.
|
||
|
*
|
||
|
* @remarks
|
||
|
* [API](https://react-hook-form.com/api/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
|
||
|
*
|
||
|
* @returns return all useForm methods
|
||
|
*
|
||
|
* @example
|
||
|
* ```tsx
|
||
|
* function App() {
|
||
|
* const methods = useForm();
|
||
|
* const onSubmit = data => console.log(data);
|
||
|
*
|
||
|
* return (
|
||
|
* <FormProvider {...methods} >
|
||
|
* <form onSubmit={methods.handleSubmit(onSubmit)}>
|
||
|
* <NestedInput />
|
||
|
* <input type="submit" />
|
||
|
* </form>
|
||
|
* </FormProvider>
|
||
|
* );
|
||
|
* }
|
||
|
*
|
||
|
* function NestedInput() {
|
||
|
* const { register } = useFormContext(); // retrieve all hook methods
|
||
|
* return <input {...register("test")} />;
|
||
|
* }
|
||
|
* ```
|
||
|
*/
|
||
|
export declare const useFormContext: <TFieldValues extends FieldValues>() => UseFormReturn<TFieldValues, any>;
|
||
|
/**
|
||
|
* A provider component that propagates the `useForm` methods to all children components via [React Context](https://reactjs.org/docs/context.html) API. To be used with {@link useFormContext}.
|
||
|
*
|
||
|
* @remarks
|
||
|
* [API](https://react-hook-form.com/api/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
|
||
|
*
|
||
|
* @param props - all useFrom methods
|
||
|
*
|
||
|
* @example
|
||
|
* ```tsx
|
||
|
* function App() {
|
||
|
* const methods = useForm();
|
||
|
* const onSubmit = data => console.log(data);
|
||
|
*
|
||
|
* return (
|
||
|
* <FormProvider {...methods} >
|
||
|
* <form onSubmit={methods.handleSubmit(onSubmit)}>
|
||
|
* <NestedInput />
|
||
|
* <input type="submit" />
|
||
|
* </form>
|
||
|
* </FormProvider>
|
||
|
* );
|
||
|
* }
|
||
|
*
|
||
|
* function NestedInput() {
|
||
|
* const { register } = useFormContext(); // retrieve all hook methods
|
||
|
* return <input {...register("test")} />;
|
||
|
* }
|
||
|
* ```
|
||
|
*/
|
||
|
export declare const FormProvider: <TFieldValues extends FieldValues, TContext = any>(props: FormProviderProps<TFieldValues, TContext>) => JSX.Element;
|
||
|
//# sourceMappingURL=useFormContext.d.ts.map
|