我遇到了这个问题。我无法在输入字段中输入任何内容。我用这个import {Field,reduxForm} from "redux-form";
但又失败了。这只是redux中的一个简单字段。我已经阅读了关于redux表单的link。没有特殊的代码和简单的应用,但当我把它播放到我的浏览器。我遇到了这个问题。
import * as React from 'react';
import {Field,reduxForm} from "redux-form";
import {connect} from 'react-redux';
class TodoForm extends React.Component<any,any>{
render(){
return (
<form>
<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>
);
}
}
const TodoFormContainer = reduxForm({
form: 'todo' // a unique name for this form
})(TodoForm);
export default connect()(TodoFormContainer);
我错过了什么吗?
答案 0 :(得分:1)
我曾经遇到过同样的问题。我记得原因是你没有在combineReducers()中添加formReducer,如下所示:
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)