面对一个奇怪的问题。我的反应应用程序中有一个输入字段。
我使用defaultValue
道具设置输入字段的值。
但是我的输入字段没有填充。它显示为空("")。但我可以在dom中看到其value属性中的值。
以下是该输入的反应道具
知道我在这里缺少什么吗?
答案 0 :(得分:1)
您只能在不受控制的组件上使用defaultValue
,但您的输入有onChange
道具,这使得它受到控制。您应该通过value
prop。
https://reactjs.org/docs/uncontrolled-components.html - 这里有一些关于它的信息。