useFormMethods
This hook allows us to use all of the methods provided by React Cool Form from a component at any level. See the Do It Yourself to learn more.
const methods = useFormMethods(formId);
#
formIdstring
The corresponding ID of the useForm
hook. We only need it when using multiple form hooks at the same time.
#
methodsThe methods are the same as the useForm
hook.
#
ExampleThe example demonstrates the basic usage of this hook.
import { useFormMethods } from "react-cool-form";
const Field = ({ as, name, onFocus, ...restProps }) => { const { clearErrors, ...otherMethods } = useFormMethods(); const Component = as;
return ( <Component name={name} onFocus={(e) => { clearErrors(name); if (onFocus) onFocus(e); }} {...restProps} /> );};