我在使用redux-forms时遇到了麻烦。提交表单时,数据对象为空。只有一个输入和一个提交按钮。这是代码,我不明白我做错了什么。
在搜索视图中:
render() {
const {submitSearchForm} = this.props;
return (
<div>
<SearchForm onSubmit={submitSearchForm}/>
</div>
);
}
和Search形式:
renderTextField = ({input, placeholder, leftIcon, rightIcon, clickableIcon, width}) => {
return <TextField placeholder={placeholder}
leftIcon={leftIcon}
rightIcon={rightIcon}
clickableIcon={clickableIcon}
width={width}
{...input}/>;
};
render() {
const {handleSubmit, fields} = this.props;
return (
<div className="row">
<form onSubmit={handleSubmit}>
<Field name="searchText"
component={this.renderTextField}
placeholder="Enter title and/or skills"
leftIcon="icon-search"
width={424}
field={fields.searchText}/>
<Button type="default"
label="go"
size="medium"
isSubmitButton={true}/>
</form>
</div>
);
}
这是我如何连接reduxForms与SearchForm:
const reduxSearchForm = reduxForm({
form: "Search",
fields: ["searchText"]
});
export default(reduxSearchForm(SearchForm));
根据文档检查了所有内容后,我发现问题出现在组合reducer时。将formReducer映射到form是非常重要的。
export const reducer = combineReducers({
form: formReducer,
search
});