useBranchValues()
Sends all values supplied to a <Form>
through the branchValues
prop. Each object key is split at the intersection of every <Section>
, <Repeat>
and <Field>
. This is useful for distributing values stored in external state that matches the shape of your form.
TypeScript
type UseBranchValues = <T = any>(name: string | number) => T
Options
name
name: string | number
The name or path of the field to retrieve the branchValues
for.
Example
Given the following <Form>
<Form
commonValues={{ data }}
branchValues={{ data }}
>
...
</Form>
This:
const { error } = useBranchValues(name)
and this:
const commonValues = useCommonValues(name)
const [, meta] = useField(name)
const error = get(commonValues.data, meta.path)
accomplish much the same thing.