react-uniformed › "useValidateAsSetter"
▸ useValidateAsSetter(validate
: ValidateAllHandler‹FieldValue›, values
: Fields): eventLikeHandlers
Creates a function that accepts a name and value as parameters. When the returned function is invoked, it will call the specified validate function with the specified values merged in with the name and value passed to the invoked function.
The main purpose of this hook is to use validate with useSettersAsEventHandler
without
validation being one update behind.
example
// used with useForms
const {validate, values, setValue} = useForms(...);
const validateAll = useValidateAsSetter(validate, values);
// now you can use validate with onChange events and keep the validation
// in sync.
const onChange = useSettersAsEventHandler(setValue, validateAll);
Parameters:
Name | Type | Description |
---|---|---|
validate |
ValidateAllHandler‹FieldValue› | a validation function that accepts an object of values. |
values |
Fields | a values object. |
Returns: eventLikeHandlers
a function that can be invoked with a name and value.
See useSettersAsEventHandler
See useSettersAsRefEventHandler