本文介绍了如何以redux形式重置初始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 redux-form.我在州的输入字段中显示初始值.当我点击重置时,输入字段仍然显示初始值.
如何重置输入字段?
这是我的代码:
const mapStateToProps = (state) =>{返回 {初始值:{名称:state.userInfo.data.name,电子邮件:state.userInfo.data.email,电话:state.userInfo.data.phone,城市:state.userInfo.data.city.name,}};}
这就是我在输入字段中调用初始值的方式.
const renderField = ({ input, label, type, meta: { touch, error } }) =>(<div><input className="form-control control_new" {...input} placeholder={label} type={type}/>{感动&&((错误&& {error}</span>))}
)<Field type="text" {...name} name="name" component={renderField} label="输入您的姓名"/>
谢谢
解决方案
import {reset} from 'redux-form';...dispatch(reset('myForm'));//需要表单名称
I'm using redux-form. I'm showing initial values in input fields from the state.When I click on reset, the input field is still showing initial values.
How can I reset the input field?
This is my code :
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,
}
};
}
This is how I'm calling initial value in the input field.
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" />
Thanks
解决方案
import {reset} from 'redux-form';
...
dispatch(reset('myForm')); // requires form name
这篇关于如何以redux形式重置初始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!