form-hooks
Advanced tools
Comparing version 0.4.0 to 0.5.0-alpha.0
{ | ||
"name": "form-hooks", | ||
"version": "0.4.0", | ||
"version": "0.5.0-alpha.0", | ||
"description": "Easy forms in React with hooks", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -60,3 +60,3 @@ # form-hooks | ||
### `useForm<Values>(options: FormHookOptions): FormHookState<Values>` - `FormHookOptions` | ||
### `useForm<Values>(options: FormHookOptions, dependencies?: FormHookDependencies<Values>): FormHookState<Values>` - `FormHookOptions` | ||
@@ -92,3 +92,3 @@ The `useForm` hook takes some options (as an object) to initialize state | ||
### `useForm<Values>(options: FormHookOptions): FormHookState<Values>` - `FormHookState` | ||
### `useForm<Values>(options: FormHookOptions, dependencies?: FormHookDependencies<Values>): FormHookState<Values>` - `FormHookState` | ||
@@ -136,2 +136,20 @@ #### `errors: FormHookErrors<Values>` | ||
### `FormHookDependencies<Values>` - Form Reinitialization | ||
The second parameter to `useForm` allows for a list of dependencies to be | ||
declared from the collection of options passed through in the first argument. For instance in this example: | ||
```ts | ||
useForm( | ||
{ | ||
initialValues: { first: 'John', last: 'Doe' }, | ||
onSubmit: () => {}, | ||
validate: () => ({}), | ||
}, | ||
options => [options.initialValues] | ||
); | ||
``` | ||
Changing the `initialValues` object will cause the Form to be re-initialized. `initialValues`, `errors`, `touched`, `submitCount` and `isSubmitting` will be reset. | ||
[formik]: https://github.com/jaredpalmer/formik |
59334
153