antdesign的Input控件加了初始化值,网站控制台暴警告,什么原因?

图片描述
这句话爆了警告
图片描述
即:Warning: Input is changing an uncontrolled input of type text to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: https://fb.me/react-controlle...
如果,我在initailValue传入不变的量string,就不会暴警告
图片描述
为什么 呢?

阅读 7.7k
4 个回答

其实就是没有初始化,

constructor(props, context) {
        this.state = {value:""};
    }
新手上路,请多包涵

我也有这样的问题,因为只是warn不是error不影响开发就没管

你报的错最后的那个链接中,有提到:A controlled <input> has a value prop。而你的代码中,并没有出现value属性。

而你将一个函数执行结果放入input中的作法,个人觉得不可取。你应事先以一个变量保存此函数的执行结果,再将变量放入input中,就如formItemLayout一样,我觉得这样更好

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题