如何使用this.props.change以redux形式更改深层字段



我想在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,
}
} 

最新更新