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)
form:String [required]
表单的名称以及表单状态将在redux-form reducer下挂载的键
我正在运行Simple Form example。我有这段代码:
var reduxFormReducer = reduxForm({
formKey: 'personal' // a unique identifier for this form
})(SimpleForm);
var reducer = combineReducers({
formKey: reduxFormReducer
});
但它显示了这个错误:
警告:道具类型失败:
form
中未指定必需道具Form(SimpleForm)
。在Form(SimpleForm)中(由Connect(Form(SimpleForm))创建)
我试过这个:
var reduxFormReducer = reduxForm({
form: 'formKey' // a unique identifier for this form
})(SimpleForm);
var reducer = combineReducers({
formKey: reduxFormReducer
});
它没有显示错误,但编辑字段为空且无法更改。
答案 0 :(得分:3)
我希望您在减速机中错过了,请使用密钥名称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/
<强>更新强>
表格减速机。应该在form
安装到Redux状态。
如果您绝对必须将其安装在form
以外的其他位置,则可以向getFormState(state)
装饰器提供reduxForm()
函数,以获取已安装的Redux状态的片段redux-form
减速机。