[英]Clear text field do not empty the input value
I'm sure I'm missing something really small but I just couldn't fine it, I'm trying to clean the text input.我确定我错过了一些非常小的东西,但我无法很好地解决它,我正在尝试清理文本输入。 I'm setting the state to ('') and it's clearing the variable but the HTML input keep the old value...我将 state 设置为 ('') 并且它正在清除变量,但 HTML 输入保持旧值...
What am I missing??我错过了什么?? https://codesandbox.io/s/cleartextfield-su3y9 https://codesandbox.io/s/cleartextfield-su3y9
Thanks for the helpers!感谢帮助者!
You are indeed missing something really small:) Please add value={searchValue}
as a prop for the TextField
component.您确实缺少一些非常小的东西:) 请添加value={searchValue}
作为TextField
组件的道具。
checkout https://material-ui.com/components/text-fields/#uncontrolled-vs-controlled结帐https://material-ui.com/components/text-fields/#uncontrolled-vs-controlled
Your component isn't controlled.您的组件不受控制。
TextField
has a value
prop. TextField
有一个value
道具。
Setting value={searchValue}
will fix it.设置value={searchValue}
将修复它。
You just forgot to pass in the value prop to the TextField component您只是忘记将 value 属性传递给 TextField 组件
https://codesandbox.io/s/cleartextfield-wppk4?from-embed https://codesandbox.io/s/cleartextfield-wppk4?from-embed
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.