我是否必须将 redux-form 挂载到状态根目录中的 "form" 键?

Do I have to mount redux-form to the "form" key in the root of my state?

getting started page 说:

import { createStore, combineReducers } from 'redux'
import { reducer as formReducer } from 'redux-form'

const reducers = {
  // ... your other reducers here ...
  form: formReducer     // <---- Mounted at 'form'
}
const reducer = combineReducers(reducers)
const store = createStore(reducer)

但是 reduxForm() documentation 说:

form : String [required]

the name of your form and the key to where your form's state will be mounted under the redux-form reducer

我是运行 Simple Form example。我有这个代码:

var reduxFormReducer = reduxForm({
  formKey: 'personal'  // a unique identifier for this form
})(SimpleForm);

var reducer = combineReducers({
  formKey: reduxFormReducer
});

但是它显示这个错误:

Warning: Failed prop type: Required prop form was not specified in Form(SimpleForm). in Form(SimpleForm) (created by Connect(Form(SimpleForm)))

我试过这个:

var reduxFormReducer = reduxForm({
  form: 'formKey'  // a unique identifier for this form
})(SimpleForm);

var reducer = combineReducers({
  formKey: reduxFormReducer
});

它没有显示该错误,但编辑字段为空且无法更改。

我希望你错过了reducer,请使用键名作为form

var reduxFormReducer = reduxForm({
  form: 'formKey'  // a unique identifier for this form
})(SimpleForm);

var reducer = combineReducers({
  form: reduxFormReducer // <- change formKey to form here 
});

参考:http://redux-form.com/6.0.2/docs/GettingStarted.md/

更新:

形式减速器。应该挂载到你的 Redux 状态 form.

如果你绝对必须将它安装在 form 以外的地方,你可以为 reduxForm() 装饰器提供一个 getFormState(state) 函数,以获取你拥有的 Redux 状态的切片安装了 redux-form 减速器。