還元型を使用しています。私は状態から入力フィールドに初期値を示しています。 リセットをクリックすると、入力フィールドにはまだ初期値が表示されます。還元型で初期値をリセットする方法
はどのようにして、入力フィールドをリセットすることができます。
これは私のコードです:
const mapStateToProps = (state) => {
return {
initialValues: {
name:state.userInfo.data.name,
email:state.userInfo.data.email,
phone:state.userInfo.data.phone,
city:state.userInfo.data.city.name,
}
};
}
これは私が入力フィールドに初期値を呼んでいる方法です。
const renderField = ({ input, label, type, meta: { touched, error } }) => (
<div>
<input className="form-control control_new" {...input} placeholder={label} type={type}/>
{touched && ((error && <span>{error}</span>))}
</div>
)
<Field type="text" {...name} name="name" component={renderField} label="Enter Your Name" />
おかげ
についてcurrent documentationです。フォームは古いinitialValuesを保持し、新しいinitialValuesに切り替えます。 – Mrchief