首页 > 解决方案 > 如何发送 redux-form 数据

问题描述

我有登录组件。这里我使用了 redux-form。由于我是新手,您能帮忙从 redux-form 获取表单数据(如何提交表单数据)吗?

<form onSubmit={this.onSubmit}>
    <div className="padding5">
        <Field name="email" type="email" component={RenderField} label="Email Id" />
    </div>
    <div className="padding5">
        <Field name="Password" type="Password" component={RenderField} label="Password" />
    </div>

    <div className='buttonSection'>
        <button type="submit" disabled={this.state.errors} className='buttonField padding5'>Reset Password</button>
    </div>
</form>

标签: javascriptreactjsredux-form

解决方案


你的代码看起来不错。您必须使用Formfrom redux-form

import { reduxForm, Form } from 'redux-form';

// Your form component
<Form onSubmit={this.onSubmit}>
  // Your form
</Form>

确保您已添加redux-form到您的 redux 商店:

import { combineReducers } from 'redux';
import { reducer as formReducer } from 'redux-form';

const combinedReducers = combineReducers({
  form: formReducer
})

并且您正在导出包装好的表单:

import { reduxForm, Form } from 'redux-form';

// Your form

export default reduxForm({
  form: 'name-of-form'
})(MyForm);

推荐阅读