1

抱歉,如果这已在其他地方得到解答,我是 Redux 初学者,我找不到任何相关内容。

我在将调度映射到 ReduxForm 时遇到问题。我像这样设置我的减速器:

import { reducer as formReducer } from 'redux-form';
import foo from './foo';
import bar from './bar';

const rootReducer = combineReducers({
  foo,
  bar,
  form: formReducer
});

export default rootReducer;

然后像这样组合它们:

import rootReducer from '../reducers/index';

const loggerMiddleware = createLogger();

const createStoreWithMiddlware = applyMiddleware(
   thunkMiddleware,
  loggerMiddleware
)(createStore);

export default function configureStore(initialState) {
  const store = createStoreWithMiddlware(rootReducer, initialState);
  return store;
}

然后将 dispatch 映射到 props,如下所示:

function mapStateToProps(state) {
  return {
    foo: state.foo,
    bar: state.bar
  }
}

function mapDispatchToProps(dispatch) {
  return {
    actions: bindActionCreators(Actions, dispatch),
  }
}

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(App)

然后我有一个表单组件,我将它包装在一个 reduxForm 中,如下所示:

TestForm = reduxForm({
  form: 'testForm',
  fields: ['firstName', 'lastName', 'email']
})(TestForm);

export default TestForm;

但我收到一个错误:

Warning: Failed propType: Required prop dispatch was not specified in ReduxForm(TestForm). Check the render method of TestFormParent.

将调度注入表单组件的最佳方法是什么?

4

2 回答 2

2

原来 npm 上的文档有点不同,而且更完整。如果其他人遇到此问题,请使用 connectReduxForm 而不是 reduxForm 解决问题。

于 2015-11-02T22:57:42.233 回答
1

reduxForm 适用于 redux-form 版本 4

于 2016-01-24T08:32:31.743 回答