// console报错信息如下
Warning: `value` prop on `input` should not be null. Consider using the empty string to clear the component or `undefined` for uncontrolled components.
in input (created by AddAddress)
in div (created by AddAddress)
in div (created by AddAddress)
in AddAddress (created by RouterContext)
in div (created by Unknown)
in div (created by Unknown)
in Unknown (created by RouterContext)
in RouterContext (created by Router)
in Router
原因解析:
由于input需要设置value,而初始化state里面的value值为null,导致react解析报Waring。
Warning: `value` prop on `input` should not be null. Consider using the empty string to clear the component or `undefined` for uncontrolled components.
解决方案:
1、waring忽略不管
2、设置input初始化值位空字符串
<input type="number" maxLength="6" placeholder="选填" value={postcode || ''} />
解决React输入框警告
本文介绍了一种常见的React警告——关于输入框value属性不应为null的问题,并提供了两种解决方案:一是忽略警告;二是将输入框的初始值设为空字符串。
1128

被折叠的 条评论
为什么被折叠?



