React-如何在 TextField 具有值时启用按钮
因此,我尝试在文本字段中输入值后立即启用按钮。启用它的唯一方法是在将值放入文本字段后单击文本字段外部。我知道我错过了一些小东西,但我仍然没有找到正确的方法。我将不胜感激你的建议。
So I'm trying to enable a button as soon as I enter a value in the TextField. The only way it is enabled is if i click outside the TextField after I put a value inside the Textfield. I know i'm missing something small but I still haven't found the correct way. I would appreciate your advice .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只包含了相关部分。
I have included only the relevant part.
您可以跟踪文本字段中的当前值并将其存储在状态中。
并编写一个在文本字段中的更改事件上触发的函数:
然后您可以调整文本字段:
然后您可以使用 set txtFieldValue 来呈现按钮,如下所示:
或者如果您只想禁用它,您可以使用
作为布尔值。
You could keep track of the current value inside your textfield and store it inside the state.
and write a function which is triggered on the change event in your textfield:
And then you can adjust your textfield:
and you can then use the set txtFieldValue to render the button like:
or if you just want to disable it you can just use the
as a boolean.