复选框的 Redux 表单 `Field` 的 `onChange` 处理程序中的 `event.target.value` 不正确
Incorrect `event.target.value` in `onChange` handler of Redux Form `Field` for checkbox
使用 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.value
是 true
但我可以看到该复选框是 未选中 。当我单击时,我第三次单击该复选框 e.target.value
是 false
,但我可以看到该复选框已被 选中 。在我看来,这种行为与
的行为不同
<Field
name="lastName"
component="input"
type="text"
placeholder="Last Name"
onChange={e => console.log(e.target.value)}
/>
其中 e.target.value
与输入字段中可见的当前值相同。
有人可以澄清这种不同的行为吗?是 React Form 的问题吗?
我正在使用 Redux Form 官方示例进行测试 https://codesandbox.io/s/mZRjw05yp
复选框的值不像 input
,复选框的值在 e.target.checked
内
使用 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.value
是 true
但我可以看到该复选框是 未选中 。当我单击时,我第三次单击该复选框 e.target.value
是 false
,但我可以看到该复选框已被 选中 。在我看来,这种行为与
<Field
name="lastName"
component="input"
type="text"
placeholder="Last Name"
onChange={e => console.log(e.target.value)}
/>
其中 e.target.value
与输入字段中可见的当前值相同。
有人可以澄清这种不同的行为吗?是 React Form 的问题吗?
我正在使用 Redux Form 官方示例进行测试 https://codesandbox.io/s/mZRjw05yp
复选框的值不像 input
,复选框的值在 e.target.checked