Phoenix
Phoenix

Reputation: 4274

How can change deep fields in redux-form with this.props.change

I want to change deep fields in redux-form with this.props.change in redux-form V6.

Here are my mapStateToProps:

function mapStateToProps(state) {
    const {recipient_type, filters} = 
    formValueSelector('form_wizard')(
    state, 'filters.recipient_type' ,'filters');

    return {
        recipient_type,
        filters
    }
}

and here is my componentDidMount (where I want to change deep field programmatically)

componentDidMount() {
    if (!this.props.recipient_type) {
        this.props.change("filters.recipient_type}", someThing);
    }
}

The result for this.props.recipient_type is undefined.

Question:

How can I change the deep field with this.props.change() in redux-form?

Thanks

Upvotes: 4

Views: 385

Answers (1)

Phoenix
Phoenix

Reputation: 4274

finally, I found the Answer

if you want to access the deep field in redux-form you must get it with parent key in formValueSelector :

function mapStateToProps(state) {
    const {filters} = 
    formValueSelector('form_wizard')(
    state, 'filters.recipient_type' );
    return {
        recipient_type : filters,
    }
} 

and if you need to get parent field:

function mapStateToProps(state) {
    const {filters} = 
    formValueSelector('form_wizard')(
    state, 'filters' );
    return {
        recipient_type : filters.recipient_type,
    }
} 

Upvotes: 1

Related Questions