Redux表单“字段”的onChange处理程序中的复选框的event.target.value不正确

时间:2019-06-23 12:46:31

标签: javascript reactjs redux-form

使用Redux Form 7.4.0测试以下代码:

<Field
  name="employed"
  id="employed"
  component="input"
  type="checkbox"
  onChange={e => console.log(e.target.value)}
/>

对我来说奇怪的是,当我第一次单击复选框时,我看到e.target.value是一个空字符串。当我第二次单击复选框时,e.target.valuetrue,但是我看到该复选框是未选中。当我单击时,我第三次单击复选框e.target.valuefalse,但可以看到该复选框已被选中。在我看来,这种行为与

的行为不同是错误的结尾
<Field
  name="lastName"
  component="input"
  type="text"
  placeholder="Last Name"
  onChange={e => console.log(e.target.value)}
/>

,其中e.target.value与在输入字段中可见的当前值相同。 有人可以澄清这种不同的行为吗?这是React Form的问题吗? 我正在使用Redux Form oficial示例来测试https://codesandbox.io/s/mZRjw05yp

1 个答案:

答案 0 :(得分:1)

该复选框的值与input不同,该复选框的值位于e.target.checked

相关问题