我有redux-form
输入字段的地方,当它被触摸时,如果有的话,它会显示错误。现在我想在重新加载页面时将输入字段触摸属性重置为false
。我该怎么做?
我正在使用redux-persist
来保持状态,所以我必须显式执行此操作,所以我需要一种方法将触摸属性设置为 false componentDidMount
.
有一段时间没有碰过redux-form
了,所以请耐心等待我的示例代码中的任何问题。
Redux-form的动作创建者可以正常用作调度程序。您只需要导入操作并在mapDispatchToProps
中使用它:
import { untouch } from 'redux-form/actions'
...
componentDidMount() {
const fieldArray = getFields() // your own methods
this.props.untouch(fieldArray)
}
...
const mapStateToProps = (dispatch) => ({
untouch: (fieldArray) => dispatch(untouch("YOUR_FORM_NAME", fieldArray))
})