From 557ef29cebb6296655192c57e62729b8a9bda099 Mon Sep 17 00:00:00 2001 From: EZZAHED Date: Sun, 17 Oct 2021 15:56:27 +0100 Subject: [PATCH] Update md file by adding a simple example the example is copied form here https://github.com/final-form/react-final-form-hooks --- docs/api/useField.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/docs/api/useField.md b/docs/api/useField.md index 1d8e6134..1737fd83 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} + )} +
+ +
+ ) +} + +```