我收到以下错误:
'dispatch' 未定义 no-undef
我想要做的是,只要用户选择 ReduxFormField 单选按钮之一,表单就会自动提交。
能够做到这一点的正确方法是什么..从 onReduxFormFieldChange 调度?
...
import {
Field as ReduxFormField,
reduxForm,
} from 'redux-form';
import { compose } from 'recompose';
...
class MyFormRadioInputs extends React.Component {
onReduxFormFieldChange = (e, newValue, previousValue) => {
if (newValue) {
dispatch(submit(MYFORM));
}
render() {
const { MyItems } = this.props;
return MyItems.map((item) => (
<ReduxFormField
key={item.id}
name="MyItemId"
type="radio"
value={item.id}
label={item.title}
onChange={this.onReduxFormFieldChange}
/>
));
}
}
const withForm = compose(
reduxForm({
form: MYFORM,
...
})
);
const MyForm = (props) => (
<Form>
<MyFormRadioInputs
myItems={props.myItems}
/>
</Form>
);
MyForm.propTypes = {
myItems: PropTypes.shape....
};
export default withForm(MyForm);