【发布时间】:2017-02-04 15:47:05
【问题描述】:
我正在使用 react-redux-forms 并关注 quick start 我创建了反应组件:
这个类包含存储定义和提供者
import React from 'react';
import { Provider } from 'react-redux';
import { createStore,applyMiddleware } from 'redux';
import { combineForms } from 'react-redux-form';
import RecordForm from './components/RecordForm.jsx'
const initRecord= {
name: '',
SUKL: '',
ATC: ''
};
const store = createStore(combineForms({
record: initRecord
}));
@translate(['record'], { wait: true })
export default class App extends React.Component {
constructor(props){
super(props);
}
render() {
const { t }= this.props;
return (
<div>
<div className="row">
<div className="row header">
<h1>
{t('record.NewRecord')}
</h1>
</div>
<div className="row">
<Provider store={ store }>
<RecordForm />
</Provider>
</div>
</div>
</div>
);
}
这是表单文件:
import React from 'react';
import { connect } from 'react-redux';
import { Control, Form } from 'react-redux-form';
export default class RecordForm extends React.Component {
constructor(props){
super(props);
}
handleSubmit(record) {
const { dispatch } = this.props;
///dispatch is undefined !!!!!!!
}
render() {
return (
<div>
<Form model="record" onSubmit={(record) => this.handleSubmit(record)}>
<Control.text model="record.name" />
<button type="submit">
OK!
</button>
</Form>
</div>
);
}
}
当我到达 handleSumbit 部分时 - dispatch 未定义。当我调试这个时,即使在 RecordForm 的构造器中,也没有在道具或与表单相关的任何内容中调度。我应该添加一些注释,例如 connect() 吗?我错过了什么?
【问题讨论】: