Programmatically change Redux-Form Field value

后端 未结 1 1681
孤街浪徒
孤街浪徒 2020-12-01 08:57

When I use redux-form v7, I find there is no way to set the field value. Now in my form, I have two select component. The second\'s va

相关标签:
1条回答
  • 2020-12-01 09:41

    You can have the onChange logic in this.handleSelectChange({ value, type: input.name }) and use change action from redux-form

    According to the docs:

    change(field:String, value:any) : Function

    Changes the value of a field in the Redux store. This is a bound action creator, so it returns nothing.

    Code:

    handleSelectChange = (value, type) => {
         if(type === "site") {
              this.props.change('net', "newValue");
         }
    }
    const mapDispatchToProps = (dispatch) => {
       return bindActionCreators({change}, dispatch);
    }
    
    0 讨论(0)
提交回复
热议问题