diff --git a/docs/api/useField.md b/docs/api/useField.md index 1d8e613..1737fd8 100644 --- a/docs/api/useField.md +++ b/docs/api/useField.md @@ -36,3 +36,41 @@ An object that looks just like [`FieldProps`](../types/FieldProps), except witho `useField()` returns [`FieldRenderProps`](../types/FieldRenderProps). It will manage the rerendering of any component you use it in, i.e. the component will only rerender if the field state subscribed to via `useField()` changes. `useField()` is used internally inside [``](Field). + + +## Example + +```ts +import { useForm, useField } from 'react-final-form-hooks' + +const MyForm = () => { + const { form, handleSubmit, values, pristine, submitting } = useForm({ + onSubmit, // the function to call with your form values upon valid submit + validate // a record-level validation function to check all form values + }) + const firstName = useField('firstName', form) + const lastName = useField('lastName', form) + return ( +
+
+ + + {firstName.meta.touched && firstName.meta.error && ( + {firstName.meta.error} + )} +
+
+ + + {lastName.meta.touched && lastName.meta.error && ( + {lastName.meta.error} + )} +
+ +
+ ) +} + +```