form-hooks
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -126,2 +126,3 @@ "use strict"; | ||
handleSubmit: handleSubmit, | ||
setErrors: setErrors, | ||
isSubmitting: isSubmitting, | ||
@@ -128,0 +129,0 @@ submitCount: submitCount |
{ | ||
"name": "form-hooks", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Easy forms in React with hooks", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -60,2 +60,62 @@ # form-hooks | ||
## Documentation | ||
### `useForm` - `options` | ||
The `useForm` hook takes some options (as an object) to initialize state | ||
and manage form validation/submissions. | ||
#### `initialValues` | ||
An object with the forms initial values. These values should not be required. | ||
#### `onSubmit(values)` | ||
Called when a form is submitted with the values set. Only called if validation | ||
passes. | ||
#### `validate(values)` | ||
Called when a form is submitted prior to the `onSubmit` call. Returns an object | ||
of errors similar to `Formik`. | ||
### `useForm` - returned | ||
#### `errors` | ||
An object that contains the form errors where the key is the field name | ||
and the value is the error message. | ||
#### `touched` | ||
An object that contains which form fields have been touched. The key is | ||
the field name, the value is a boolean of if the field has been touched. | ||
#### `values` | ||
An object that contains all of the values of the form. Initialized with the | ||
`initialValues` originally passed in. Modified by the `handleChange` handler. | ||
#### `handleBlur` | ||
Marks a field as `touched` to show errors after all fields are touched. | ||
#### `handleChange` | ||
Changes the fields value in the `values` state. | ||
#### `handleSubmit` | ||
Handles calling validation prior to the `onSubmit` handler and setting the | ||
`touched`, `errors` and `isSubmitting` state internally. | ||
#### `isSubmitting` | ||
Boolean value if the form is currently submitting. | ||
#### `setErrors` | ||
Function that allows for errors to be set outside of the `useForm` | ||
internal handlers (good for handling request errors). | ||
[Formik]: https://github.com/jaredpalmer/formik |
9275
100
120