Redux形式不起作用

时间:2017-07-12 16:16:24

标签: reactjs redux react-redux redux-form

我正在尝试使用redux-form。我按照文档,但当我在输入框中输入内容时似乎没有任何事情发生(输入中没有字母出现)。当我查看控制台时,我可以看到该动作已发送。附上截图。

check dispatched action and next state, it returns a form() function

  

我在减速机中没有使用>>> 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;

1 个答案:

答案 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

希望这会有所帮助。快乐的编码!