Skip to content

Commit

Permalink
Use better generic parameter names
Browse files Browse the repository at this point in the history
  • Loading branch information
rzane committed Jul 31, 2020
1 parent d70860c commit 2da100c
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 81 deletions.
62 changes: 31 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ If your form doesn't require validation, see [useNoValidate](#usenovalidate).

#### Parameters

- `options` **[FormOptions](#formoptions)<T, R>**
- `options` **[FormOptions](#formoptions)<Value, Result>**

#### Examples

Expand All @@ -152,7 +152,7 @@ const form = useForm({
});
```

Returns **[Form](#form)<T, R>**
Returns **[Form](#form)<Value, Result>**

### useField

Expand Down Expand Up @@ -188,7 +188,7 @@ This hook is intended for use in building forms with "Add another" functionality

#### Parameters

- `field` **[FormField](#formfield)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<T>>**
- `field` **[FormField](#formfield)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<Value>>**
- `index` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**

#### Examples
Expand All @@ -205,7 +205,7 @@ const pet = useFieldItem(pets, 0);
const name = useField(pet, "name");
```

Returns **[FormField](#formfield)<T>**
Returns **[FormField](#formfield)<Value>**

### useNoValidate

Expand All @@ -221,15 +221,15 @@ const form = useForm({
});
```

Returns **[Validate](#validate)<T, T>**
Returns **[Validate](#validate)<Value, Value>**

### useValidator

Use a validation schema produced by [@stackup/validate](https://github.com/rzane/validate)

#### Parameters

- `validator` **Validator<T, R>**
- `validator` **Validator<Value, Result>**

#### Examples

Expand All @@ -248,7 +248,7 @@ const form = useForm({
});
```

Returns **[Validate](#validate)<T, R>**
Returns **[Validate](#validate)<Value, Result>**

### usePushItem

Expand All @@ -258,8 +258,8 @@ This can be used to create a form with repeating fields.

#### Parameters

- `field` **[FormField](#formfield)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<T>>**
- `value` **T**
- `field` **[FormField](#formfield)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<Value>>**
- `value` **Value**

#### Examples

Expand All @@ -277,9 +277,9 @@ This can be used to create a form with repeating fields.

#### Parameters

- `field` **[FormField](#formfield)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<T>>**
- `field` **[FormField](#formfield)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<Value>>**
- `index` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
- `value` **T**
- `value` **Value**

#### Examples

Expand All @@ -297,7 +297,7 @@ This can be used to create a form with repeating fields.

#### Parameters

- `field` **[FormField](#formfield)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<T>>**
- `field` **[FormField](#formfield)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<Value>>**
- `index` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**

#### Examples
Expand Down Expand Up @@ -334,31 +334,31 @@ Type: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Globa

Handles the submission of the form.

Type: [Submit](#submit)<R>
Type: [Submit](#submit)<Result>

#### validate

Validates the form.

Type: [Validate](#validate)<T, R>
Type: [Validate](#validate)<Value, Result>

#### initialValue

The initial values for the form.

Type: T
Type: Value

#### initialError

The initial errors on the fields.

Type: FormError<T>
Type: FormError<Value>

#### initialTouched

The initially touched fields.

Type: FormTouched<T>
Type: FormTouched<Value>

#### validateOnChange

Expand All @@ -374,27 +374,27 @@ Type: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Glob

### Form

**Extends FormField<T>**
**Extends FormField<Value>**

The value returned by `useForm`.

#### initialValue

The initial values for the form.

Type: T
Type: Value

#### initialError

The initial errors on the fields.

Type: FormError<T>
Type: FormError<Value>

#### initialTouched

The initially touched fields.

Type: FormTouched<T>
Type: FormTouched<Value>

#### isSubmitting

Expand All @@ -418,7 +418,7 @@ Type: function (): [Promise](https://developer.mozilla.org/docs/Web/JavaScript/R

Trigger form validation.

Type: function (): [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[ValidationResult](#validationresult)<T, R>>
Type: function (): [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[ValidationResult](#validationresult)<Value, Result>>

#### onSubmit

Expand Down Expand Up @@ -446,44 +446,44 @@ Type: ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Glob

The current value of the field.

Type: T
Type: Value

#### error

An error or errors that are associated with this field or it's children.

Type: FormError<T>
Type: FormError<Value>

#### touched

Indicates that this field or it's children have been modified by the user.

Type: FormTouched<T>
Type: FormTouched<Value>

#### setValue

Change the value. Just like with `setState`, you can pass a callback
to this function to get the current value and update it.

Type: SetState<T>
Type: SetState<Value>

#### setError

Update the error.

Type: SetState<FormError<T>>
Type: SetState<FormError<Value>>

#### setTouched

Indicate that this field has been touched. This is usually called in `onBlur`.

Type: SetState<FormTouched<T>>
Type: SetState<FormTouched<Value>>

### Validate

A function that is called to validate the form.

Type: function (value: T): ([ValidationResult](#validationresult)<T, R> | [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[ValidationResult](#validationresult)<T, R>>)
Type: function (value: Value): ([ValidationResult](#validationresult)<Value, Result> | [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[ValidationResult](#validationresult)<Value, Result>>)

### ValidationResult

Expand All @@ -495,11 +495,11 @@ Many validation libraries support casting the data that you input. The
The `error` should have the same shape of your form data, but all of the
values should be strings.

Type: ({valid: `true`, value: R} | {valid: `false`, error: FormError<T>})
Type: ({valid: `true`, value: Result} | {valid: `false`, error: FormError<Value>})

### Submit

The function called when the form is submitted. The data will be validated
and converted before this function is called.

Type: function (value: T): (void | [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<void>)
Type: function (value: Result): (void | [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<void>)
Loading

0 comments on commit 2da100c

Please sign in to comment.