Redux-Form dispatch 调用 Action Creator,但 reducer 从未接收到 Action

Redux-Form dispatch calls Action Creator, but the reducer never receives Action

在下面的示例中,我使用 mapDispatchToPropsonSubmit 事件绑定到 save() Action Creator。这有效 - save() Action Creator 将消息记录到控制台。

问题在于它不会随后分派 'TEST_SAVE' 操作 - 即减速器永远不会收到类型为 'TEST_SAVE' 的操作。

我有一个 vanilla redux 表单,如下所示,但我是 redux-form 的新手,我想知道我可能做错了什么?

const reducers = {
  // ... your other reducers here ...
  form: formReducer.plugin({
    contact: (state, action) => {  
      switch(action.type) {
        case 'TEST_SAVE':
          return state;
        default:
          return state;
      }
    }
  })
};
const reducer = combineReducers(reducers);
const store = createStore(reducer);


function mapDispatchToProps(dispatch) {
  return {
    onSubmit: (val) => dispatch(actionCreators.save(val)),
  }
}

var actionCreators = {   
  save: (value) => {
    console.log('SAVE action done!');
    return {type: 'TEST_SAVE', value};
  }, 
};

const MyContactForm = connect(
  mapDispatchToProps
)(ContactForm)


<Provider store={store}>
    <MyContactForm />
</Provider>

ContactForm 的摘录 class:

class ContactForm extends Component {

  render() {
    const { error, handleSubmit, pristine, reset, submitting } = this.props;

    return (
      <form
        onSubmit={handleSubmit}
        >

    ....

    )

  }
}

ContactForm = reduxForm({
  form: 'contact' 
})(ContactForm);

切勿在减速器中使用 break。始终 return 状态对象。

const MyContactForm = connect(
  mapDispatchToProps
)(ContactForm)

connect() 的第一个参数是 mapStateToProps,而不是 mapDispatchToProps。应该是:

const MyContactForm = connect(
  undefined, // <------------- mapStateToProps
  mapDispatchToProps
)(ContactForm)