如何使用this.props.change更改redux-form中的深层字段

问题描述 投票:3回答:1

我想用redux-form中的this.props.change改变redux-form V6的深场。

这是我的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的结果未定义。

如何在this.props.change()中用redux-form改变深场?

谢谢

reactjs redux
1个回答
1
投票

最后,我找到了答案

如果要以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,
    }
} 
© www.soinside.com 2019 - 2024. All rights reserved.