[英]Reactjs: input field has value but showing as empty
Facing a weird issue. 面对一个奇怪的问题。 I have an input field in my react app.
我的应用程序中有一个输入字段。 I am setting the value of my input field using the
defaultValue
prop. 我正在使用
defaultValue
设置输入字段的值。 But my input field is not populating. 但是我的输入字段没有填充。 Its showing as empty ( "" ).
它显示为空 (“”)。 But i can see the value in its value attribute in the dom.
但是我可以在dom的value属性中看到该值。
Here are the react props of that input 这是该输入的反应道具
Any idea what i am missing here? 知道我在这里缺少什么吗?
You could use defaultValue
only on uncontrolled components, but your input have onChange
prop, and that makes it controlled. 您只能在不受控制的组件上使用
defaultValue
,但是您的输入具有onChange
defaultValue
,这使其受到控制。 You should set your default value through the value
prop. 您应该通过
value
属性设置默认值。
https://reactjs.org/docs/uncontrolled-components.html - here some info about it. https://reactjs.org/docs/uncontrol-components.html-有关此的一些信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.