我正在尝试使用redux-form。我按照文档,但当我在输入框中输入内容时似乎没有任何事情发生(输入中没有字母出现)。当我查看控制台时,我可以看到该动作已发送。附上截图。
我在减速机中没有使用
>>> x = 42 >>> x = 'shrubbery' # Reclaim 42 now?
。是否有必要使用combineReducers
?
登录表单
combineReducers
减速
import React, { Component } from 'react';
import { Field, reduxForm } from 'redux-form';
class LoginForm extends Component {
render() {
const { handleSubmit } = this.props;
return (
<form onSubmit={handleSubmit}>
<div>
<label htmlFor="firstName">First Name</label>
<Field name="firstName" component="input" type="text"/>
</div>
<div>
<label htmlFor="lastName">Last Name</label>
<Field name="lastName" component="input" type="text"/>
</div>
<div>
<label htmlFor="email">Email</label>
<Field name="email" component="input" type="email"/>
</div>
<button type="submit">Submit</button>
</form>
);
}
}
LoginForm = reduxForm({
form: 'LoginFormForm' // a unique name for this form
})(LoginForm);
export default LoginForm;
答案 0 :(得分:2)
您必须将formReducer
传递给root redurs index.js文件中的combinedReducer
调用。这是示例代码。
import { combineReducers } from 'redux';
import OtherReducer from './reducer_posts';
import { reducer as formReducer } from 'redux-form'
const rootReducer = combineReducers({
posts: OtherReducer,
form: formReducer
});
export default rootReducer;
请查看其他信息here。
希望这会有所帮助。快乐的编码!