react-final-form 状态不包含空输入

react-final-form state does not contains empty inputs

当用户从输入中删除内容时,我希望在状态中包含 empty/null 属性。

如果您在示例中看到用户清除输入时状态为空。我使用状态来更新数据库中的数据,因此当代码用新数据更新旧数据时,值不会更新(没有 属性!)。

示例:https://codesandbox.io/s/3qvqnv6216

我找不到任何聪明的方法来将 属性 留在状态中。

谢谢:)

试试这个:

<Field
  name="myfield"
  component="input"
  type="text"
  allowNull                                      // <-------
  parse={value => (value === "" ? null : value)} // <-------
/>