📋 React Hooks for form state management and validation (Web + React Native)
MIT License
Published by bluebill1049 about 5 years ago
watch(name)
name
is not in the form and leads to app crashPublished by bluebill1049 about 5 years ago
setState
after submitPublished by bluebill1049 about 5 years ago
useCallback
and making methods safe to use within useEffect
Published by bluebill1049 about 5 years ago
errors
object type: errors
object should be consist instead of a different type. related to issues: https://github.com/bluebill1049/react-hook-form/issues/135 https://github.com/bluebill1049/react-hook-form/issues/136
Published by bluebill1049 about 5 years ago
watch
API update:
watch
return default value change:
watch(['test', 'test1']) // deafult value return [undefined, undefined] instead of undefined
watch() // default value return {} instead of undefined
watch
integrate with defaultValues
watch
will inherit from data in defaultValues
, but watch function arguments remain unchanged. second argument defaultValue
will overwrite data in defaultValues
which set up in useForm()
watch
now support nested object look up
eg
const data = watch('test');
console.log(data);
<form>
<input name="test[0]" ref={register} />
<input name="test[1]" ref={register} />
</form>
this above example will watch both test[0]
and test[1]
defaultValues
update:
defaultValues
now support nested object, eg:
const { register } = useForm({
defaultValues: { test: {data: [1, 2]}},
})
getValues
update:
getValues
now support nest
argument to return data in a nested format, eg:
getValues(); // {'test[0]': 1, 'test[1]': 2}
getValues({ nest: true }); // {test: [1,2]}
setError
update:
you can no longer clear an error with setError
use clearError
instead
Published by bluebill1049 about 5 years ago
min
and max
which 0
and a negative number will not be considered to be validatedPublished by bluebill1049 about 5 years ago
setError
during submit methodPublished by bluebill1049 about 5 years ago
Fixes #136
Changes:
ErrorMessages
now can have an object using either strings
or Error
objects for values. (This is what fixes #136)Omit
, it is included in v3.5 of Typescript (https://devblogs.microsoft.com/typescript/announcing-typescript-3-5/#the-omit-helper-type)Record<key, value>
(https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html#partial-readonly-record-and-pick)Mode
as a typeVoidFunction
and NumberOrString
Data[Name]
to Value
in the FormProps
interface.object
instead of {}
Published by bluebill1049 about 5 years ago
Published by bluebill1049 about 5 years ago
Published by bluebill1049 over 5 years ago
setError
at submit https://github.com/bluebill1049/react-hook-form/issues/140errors
object gets reset after successful submiterrors
object will not clear custom error unless called with clearError
Published by bluebill1049 over 5 years ago
getValues()
Published by bluebill1049 over 5 years ago
getValues()
which data formate for array
data is incorrectExample below:
function App() {
const { register, getValues } = useForm({
defaultValues: { test: [0, 1] }
});
console.log(getValues()); // { test: [0, 1]}
return (
<form>
<input name="test[0]" ref={register} type="checkbox" />
<input name="test[1]" ref={register} type="checkbox" />
</form>
);
}
Published by bluebill1049 over 5 years ago
Published by bluebill1049 over 5 years ago
reset
in useEffect #126Published by bluebill1049 over 5 years ago
setError
https://github.com/bluebill1049/react-hook-form/issues/124
Published by bluebill1049 over 5 years ago
Published by bluebill1049 over 5 years ago
unregister
methodreset
when the first item in the filed list is manually registered fieldPublished by bluebill1049 over 5 years ago
triggerValidation()
with empty arugment to valdiate the whole formPublished by bluebill1049 over 5 years ago
triggerValidatin