useFormContext

Knowledge Base

Accepts a context object (the value returned from React.createContext) and returns the current context value for that context. The current context value is determined by the value prop of the nearest <MyContext.Provider> above the calling component in the tree.

Description

The useFormContext allow you to use the useForm state in another components in the same tree.

When you use this hook, make sure that you have a FormContextProvider in the root of the components tree.

PropertyDescription
errorsObject with all errors, this object is the same shape of object values.
isValidBoolean property

Usage

jsx
import UserFormContext from './'
function Form(){
const form = useForm(...)
return (
<FormContext.Provider value={form}>
<ChildForm1/>
<ChildForm2/>
</FormContext.Provider>
)
}
function ChildForm1(){
const { state, register,... } = useFormContext()
return(
<>
{/* component conte t */}
</>
)
}
function ChildForm2(){
const { state, register,... } = useFormContext()
return(
<>
{/* component conte t */}
</>
)
}

If you want to know more about useForm, please, visit this page useForm.

More details about React context React Docs.