我想在redux-form
中更改深场,并在redux-form V6
中更改this.props.change
。
这是我mapStateToProps
:
function mapStateToProps(state) {
const {recipient_type, filters} =
formValueSelector('form_wizard')(
state, 'filters.recipient_type' ,'filters');
return {
recipient_type,
filters
}
}
这是我的componentDidMount
(我想以编程方式更改深场(
componentDidMount() {
if (!this.props.recipient_type) {
this.props.change("filters.recipient_type}", someThing);
}
}
this.props.recipient_type
的结果未定义。
问题:
如何在redux-form
中用this.props.change()
改变深场?
谢谢
终于,我找到了答案
如果你想访问redux-form中的深层字段,你必须在formValueSelector中使用父键获取它:
function mapStateToProps(state) {
const {filters} =
formValueSelector('form_wizard')(
state, 'filters.recipient_type' );
return {
recipient_type : filters,
}
}
如果您需要获取父字段:
function mapStateToProps(state) {
const {filters} =
formValueSelector('form_wizard')(
state, 'filters' );
return {
recipient_type : filters.recipient_type,
}
}