使用 availity-reactstrap-validation 时如何处理空值

How to handle null values when using availity-reactstrap-validation

使用 availity-reactstrap-validation,当表单字段 (AvField) 填充了来自后端的空数据时,我收到一条警告:

Warning: value prop on input should not be null. Consider using an empty string to clear the component or undefined for uncontrolled components.

我尝试用空字符串交换 null 值,如警告所说,但无济于事。

<AvField type="text" name="offerKey" value={ data.offerKey === null ? '' : data.offerKey } />

如果添加空白 space 作为值,警告会消失,但占位符文本不会出现在文本框中。

这是错误还是功能?

您可以在 null 或空字符串 ('') 的状态下设置您的值

state = {
value: ''
}

或者你可以改变你的逻辑:

value={ data && data.offerKey ? data.offerKey : '' }