问题描述
也许这只是一个基本问题,但是到目前为止还没有找到任何合理的解释.我是最近开始使用React并使用material-ui的初学者.我不清楚何时使用Input vs. Textfield构建表单?
Maybe this is just a basic question, but so far have not found any reasonable explanation. I am a beginner in react and using material-ui very recently. I am not very clear on when to use an Input vs. Textfield for building a form?
看看文档,感觉TextField是Input可以做的事情的超集,但不确定. Material-ui站点在文本字段和输入示例中都使用了示例,而没有说明一个相对于另一个以及任何用例的好处.
Looking at documentation, it feels like TextField is a superset of what Input can do, but not sure. Material-ui site uses examples for text field and input both, without stating benefits of one over the other and any use cases.
请提出建议.
推荐答案
在大多数情况下,应该使用TextField
而不是它委派给的下级组件(例如Input
).
For most use cases, you should use TextField
rather than the lower-level components that it delegates to (such as Input
).
文档的相关部分在这里: https://material-ui. com/demos/text-fields/#components .
The relevant part of the documentation is here: https://material-ui.com/demos/text-fields/#components.
特别是这一行:
使用这些较低级组件的主要原因是,您是否需要以某种方式自定义表单输入,而使用TextField
不支持这种方式.
The main reason to use these lower-level components is if you need to customize your form input in some way that isn't supported using TextField
.
这篇关于在Material-ui中,何时使用输入与文本字段来构建表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!