Warning: `value` prop on `input` should not be null.

// 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 || ''} />

扫描二维码关注公众号,回复: 334026 查看本文章

猜你喜欢

转载自qiaolevip.iteye.com/blog/2344381