Skip to main content

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);

formId#

string

The corresponding ID of the useForm hook. We only need it when using multiple form hooks at the same time.

methods#

The methods are the same as the useForm hook.

Example#

The 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}    />  );};