useFormContext
React custom hook for getting the enclosing FormContextProps
provided by FormProvider
.
import { useFormContext } from '@jcoreio/zod-forms'
export function useFormContext<T extends z.ZodTypeAny>(): FormContextProps<T>
You must pass an explicit schema type for T
unless you use the useFormContext
returned by createZodForm
.
Returns FormContextProps<T>
An object with the following properties:
schema
- the Zod schema for the form valuesinverseSchema
- the inverse Zod schema;inverseSchema.parse(values)
formats to raw valuesroot
- the rootFieldPath
initialize
- method to initialize the form with initial valuesaddHandlers
- method to register submit handlersremoveHandlers
- method to unregister submit handlerssetMeta
- method to set theFieldMeta
of a fieldsetRawValue
- method to set the raw value of a fieldsetValue
- method to set the value of a fieldsubmit
- method to trigger form submitsetSubmitStatus
- method to set the submit statussubmitting
- whether the form is currently submittingsubmitError
- the reason submit failed, if anysubmitSucceeded
- whether submit succeededsubmitFailed
- whether submit failedsubmittedValues
- the values that were submittedrawSubmittedValues
- the raw values at submit timearrayActions
- methods for manipulating array fieldsinsert
- insert a value into the arrayinsertRaw
- insert a raw value into the arraymove
- move a value from one index to anotherpop
- remove the last value from the arraypush
- add a value to the end of the arraypushRaw
- add a raw value to the end of the arrayremove
- remove a value at an indexremoveAll
- remove all valuessplice
- remove and/or insert values, likeArray.splice
spliceRaw
- remove and/or insert raw values, likeArray.splice
swap
- swap values at two indicesunshift
- add a value to the beginning of the arrayunshiftRaw
- add a raw value to the beginning of the array
getValues
- get the current field valuesgetRawValues
- get the current raw field valuesgetInitialValues
- get the initial field valuesgetRawInitialValues
- get the raw initial field values