Module: "useValidateAsSetter"

May 22, 2020 · View on GitHub

react-uniformed"useValidateAsSetter"

Module: "useValidateAsSetter"

Index

Functions

Functions

useValidateAsSetter

useValidateAsSetter(validate: ValidateAllHandlerFieldValue›, 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:

NameTypeDescription
validateValidateAllHandlerFieldValuea validation function that accepts an object of values.
valuesFieldsa values object.

Returns: eventLikeHandlers

a function that can be invoked with a name and value.
See useSettersAsEventHandler
See useSettersAsRefEventHandler