useAsyncValidation
useAsyncValidation(validator: Function)
provides the async validation logic to any Field.
const [asyncStatus, validationAsyncAttr] = useAsyncValidation(fn);
Arguments
validator
: function
- A function which receives the value of the field and returns a promise.
Returns
(validationAsyncProps
): array
An array that holds:
asyncStatus
: objectA plain object that holds a prop named
status
and a prop namedvalue
.status
might be one of the following:- "undefined" : async validation did not start yet
- "asyncStart" : async validation has started
- "asyncSuccess" : the promise has been resolved with success
- "asyncError" : the promise has been rejected
value
is the value returned by the promise
validationAsyncAttr
: object- A plain object which contains all the props that must be spreaded to the Field.
Basic usage
import { Form, Input, useAsyncValidation } from 'usetheform'
- {} 0 keys