From 74abea76c9b112ce1edee12f551304426686875f Mon Sep 17 00:00:00 2001 From: Nicco Date: Sat, 28 Sep 2019 20:01:55 +0200 Subject: [PATCH] Update README.md --- README.md | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/README.md b/README.md index a977168..649dbe6 100644 --- a/README.md +++ b/README.md @@ -291,3 +291,92 @@ export default () => { }; ``` + +### Auto + +The `auto` object is used to bind the form state to the input. + + +###### Example: Simple + +```javascript +const { auto } = useForm() + + +``` + + +###### Example: With custom options + +All are optional. + +```javascript +const { auto } = useForm() + + e.target.value +})} /> +``` + +## Form + +This is the form state that you can use when submitting the data + +###### Example + +```javascript + +const { form } = useForm(...); + +// ... + +
console.log(form)}> + // ... +
+``` + +## Errors + +This object contains the error messages if a field is not valid. +The error message can be specified by you, otherwise it will return `Error in ${field}` + +###### Example + +```javascript +const { errors } = useForm(...) + +//... + +{errors.username} +{errors.password} +``` + +###### isValid + +`isValid` is a little simple helper that checks whether the `error` object is clear or if there are errors left. + +## Update + +The `update` function allows you to manually change and assign the state of the form. This can be usefull when you want to reset a field or the whole form. The input must have the same type as the initial state. + +###### Example + +```javascript +const { form, update } = useForm(...) + +const resetUsername = () => { + update({ + ...form, + username: '', + }) +} + +const resetForm = () => { + update({ + username: '', + password: '', + }) +} +```