Redux-Form update field value from external interaction

前端 未结 1 1457
醉话见心
醉话见心 2021-01-02 02:30

I have a redux-form connected to my application state and everything seems to work great. I can fetch data and load it into my form, then submit data and get the metadata I

1条回答
  •  滥情空心
    2021-01-02 02:42

    You can use react-redux's mapDispatchToProps together with the change action creator in order to achieve what you want:

    import { Component } from "react";
    import { connect } from "react-redux';
    import { change } from "redux-form";
    
    class ColorSelect extends Component {
      // ...other stuff in this class...
    
      renderColor (color) {
        const { selectColor } = this.props;
        return 
  • selectColor(color)}>
  • ; } } export default connect(null, { selectColor: color => change( "yourFormName", "yourFieldName", color ) })(ColorSelect)

    0 讨论(0)
提交回复
热议问题