reactjs - react-hook-form 不发送 PasswordConfirm
问题描述
大家好,我正在使用 react-hook-form 库,这对我来说真的很棒!
但此时我有一些问题我不想发送 pwdConfirm 值,因为这个值让我 400 错误,所以我如何在没有 pwdConfirm 的情况下发送值?
我只想发送 id、pwd、昵称!
const dispatch = useDispatch();
const { register, watch, errors, handleSubmit } = useForm();
const password = useRef();
password.current = watch('password');
const type = 'normal';
const onSubmit = (data) => {
console.log(data);
dispatch(signUpRequest(data));
};
useEffect(() => {});
return (
<>
<form
onSubmit={handleSubmit(onSubmit)}
className={styles.signup__form}
>
<label>email</label>
<input
name="email"
type="text"
ref={register({ required: true, pattern: /^\S+@\S+$/i })}
placeholder=""
/>
{errors.email && (
<p className={styles.error__message}>
incorrect email
</p>
)}
<label>password</label>
<input
name="password"
type="password"
ref={register({ required: true, minLength: 6 })}
placeholder=""
/>
{errors.password && errors.password.type === 'required' && (
<p className={styles.error__message}>
password plz
</p>
)}
{errors.password && errors.password.type === 'minLength' && (
<p className={styles.error__message}>
at least 6character
</p>
)}
<label>password confirm </label>
<input
type="password"
name="pwdConfirm"
ref={register({
required: true,
validate: (value) => value === password.current,
})}
placeholder=""
/>
{errors.pwdConfirm && errors.pwdConfirm.type === 'required' && (
<p className={styles.error__message}>
check your password
</p>
)}
{errors.pwdConfirm && errors.pwdConfirm.type === 'validate' && (
<p className={styles.error__message}>
not correct your password
</p>
)}
解决方案
我已经使用javascript从现有对象delete operator
中删除密钥。pwdConfirm
const onSubmit = (data) => {
delete data.pwdConfirm
console.log(data);
dispatch(signUpRequest(data));
};
推荐阅读
- kubernetes - Helm 图表的模板
- python - 无法连接到部署在 kubernetes 集群上的服务器
- flutter - TextEditingController 与 OnChanged
- node.js - Openlayers 无法从 RestfulAPI(节点)显示 GeoJSON Vectorlayer
- ionic-framework - 我对用于打印 ionic 4 的 ionic 本机插件有问题
- javascript - 一种扁平化对象的优雅方式
- neo4j - neo4j 的性能问题
- vue.js - 在另一个 props 的验证器中访问 props 值
- python-3.x - zarr.consolidate_metadata 产生错误:“memoryview”对象没有属性“decode”
- python - 带有 MXNet 的 Keras 中的 Conv3D:张量形状错误