【问题标题】:Redux: form input fields stay blankRedux:表单输入字段保持空白
【发布时间】:2016-11-06 20:00:24
【问题描述】:

我使用this template 安装了redux-form,连接了reducer 并检查它在redux devtools 中运行良好。

我可以看到打字时的动作流程很好,但每次击键后表单值和输入都是空的。

控制台中没有错误,我找不到任何线索。

我遗漏了一些小东西,可能是组件渲染,也可能是关于 react 版本...

我的包裹:

"react": "15.3.2",
"redux-form": "^6.2.0",

我的登录表单:

import React from 'react';
import { Field, reduxForm } from 'redux-form/immutable';


const renderField = ({ input, label, type, meta: { touched, error } }) => {
  console.log(input);
  return (
    <div>
      <label>{label}</label>
      <div>
        <input {...input} placeholder={label} type={type} />
        {touched && error && <span>{error}</span>}
      </div>
    </div>
  );
};

class FormLogin extends React.Component { // eslint-disable-line react/prefer-stateless-function
  static propTypes = {
    handleSubmit: React.PropTypes.func
  };
  render() {
    const { error, handleSubmit } = this.props;
    return (
      <div>
        <input type="text" name="ah1" />
        <form onSubmit={handleSubmit}>
          <input type="text" name="ah2" />
          <div>
            <Field id="username" name="username" type="text" component={renderField} label="Username" />

          </div>
          <div>
            <Field id="password" name="password" type="text" component={renderField} label="Password" />
          </div>
          {error && <strong>{error}</strong>}
          <button type="submit">Submit</button>
        </form>
      </div>
    );
  }
}

export default reduxForm({
  form: 'FormLogin'
})(FormLogin);

【问题讨论】:

    标签: javascript reactjs react-jsx redux-form react-boilerplate


    【解决方案1】:

    对我来说,我没有用示例中的确切名称为减速器命名,不幸的是,这导致了这个难以调试的错误。

    确保reducer 被列为'form: formReducer',如示例所示。

    【讨论】:

    • 你是我的英雄!
    【解决方案2】:

    如果有人来这里寻找答案,就会发现问题。

    有一个 hack 可以修复它。 你可以在这里找到更多: https://github.com/mxstbr/react-boilerplate/issues/958

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多