【问题标题】:redux-form fields parameters are emptyredux-form 字段参数为空
【发布时间】:2017-01-25 17:04:41
【问题描述】:

我对@9​​87654327@ 有一些问题,基本上handleSubmit 传递给它接收的函数的参数是空的...

让我描述一下我的文件(为了清楚和简洁起见,我将使用一个要点):

  1. The stateless component
  2. The Container
  3. The reducer
  4. The renderLoginField

如果你能在这一行看到:<form onSubmit={handleSubmit(this.onFormSubmit.bind(this))}>

还有这个超简单的功能:

onFormSubmit(fields) {
  console.log(fields);
};

字段为空,但form reducer 处于活动状态,并且存在已注册字段:

有什么想法吗?

【问题讨论】:

  • 你使用的是什么版本?
  • @gustavohenke im 使用"redux-form": "^6.4.3",并且对象不是未定义的,是空的(为此感到羞耻)。我想不出问题。
  • 再仔细看看,你忘了告诉我们你的renderLoginField 功能是什么!
  • 完成,我将函数添加到要点和行的链接。 renderLoginField 只是一个无状态组件,用redux-form/Field 组件渲染表单字段。

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


【解决方案1】:

您的 renderLoginField 函数,它呈现自定义字段组件(d'oh!)没有使用 input 属性。

这是您的 renderLoginField 函数的正确更改代码:

const renderLoginField = ({icon, input, type, meta: { touched, error }}) => {
  let mailIcon = 'fa-envelope-o';
  let passIcon = 'fa-key';
  return (
    <div className='form-group input-group'>
      <span className='input-group-addon' id='email'>
        <i className={`fa ${icon === 'mail' ? mailIcon : passIcon}`} />
      </span>
      <input
        { ...input } // <-- missing in your code!!
        type={type}
        aria-describedby={type}
        name={input.name}
        placeholder={`Insert ${type}`}
        className='form-control'/>
    </div>
  );
};

如果您查看the docs for &lt;Field&gt; component,您会看到以下声明,其中描述了这样做的重要性:

输入道具

input 键下的 props 是将你的输入组件连接到 Redux 的东西 并且旨在被解构为您的&lt;input/&gt; 组件

【讨论】:

    猜你喜欢
    • 2016-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 2019-03-27
    • 2017-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多