learn react-hook-form
12 Nov 2024
type=number|date
(validateAsNumber|validateAsDate)
- touched表示被触碰过,
dirty
表示和之前的value
不一样(touchFields|dirtyFields|isDirty)
mode: onSumit(default)|onTouched|onChange|all
watch(value|[value])
实时监听real-time-listening
getField|setField
phoneNumber: [1,2,3]
, phoneNumber.0
, phoneNumber.1
soical{twitter, facebook}
, social.twitter
, social.facebook
required, pattern, maxLength, minLength, max, min, validate: (value) => true|string
<form onSumbit={handleSubmit(onSumbit(data), onError(error))} noValidate>
- control,
react-hook-form dev tool
- formState:
isValid|isDirty submit button
- register =>
name, value, onChange, onBlur
<DevTool control={control>
isSubmitting|isSubmitted|isSubmitSuccessful
submitCount
计算成功的次数
useWatch
,需要包含在FormProvider或者传递control参数, 对于性能有帮助, 集中到component的re-render, 减少外部的re-render