【问题标题】:Typescript error adding hintText to a TextField in create-react-app-with-typescript在 create-react-app-with-typescript 中将提示文本添加到 TextField 的 Typescript 错误
【发布时间】:2018-08-28 11:11:32
【问题描述】:

刚刚下载、安装并运行 create-react-app-with-typescript,我一直在试验各种组件。当我使用以下几行添加带有hintText的TextField时:

import TextField from 'material-ui/TextField';

  <TextField hintText="Hint Text"/><br />
  <Typography variant="display1" gutterBottom>
    Material-UI
  </Typography>

我收到以下错误:

(56,20): Type '{ hintText: string; }' has no properties in common with type 'IntrinsicAttributes & TextFieldProps & { children?: ReactNode; }'.

material-ui 版本为 1.0.0-beta.38。 打字稿版本是 2.7.2。

我尝试包含 @types/material-ui,但这会产生许多其他问题(根据阅读其他帖子,此版本的 material-ui 预计会出现这些问题)。

想法?

更新:我刚刚注意到的一件事是,如果我在克隆 repo 后通过在 docs 目录中运行 npm start 来查看文档,这些示例与我在此处找到的示例有些不同:http://www.material-ui.com/#/components/app-bar

【问题讨论】:

    标签: reactjs typescript material-ui


    【解决方案1】:

    您正在使用新版本的 Material-UI,其中 hintText 属性已被 placeholder 替换。您应该可以使用:

    <TextField placeholder="something" />
    

    更多例子请见她:https://material-ui-next.com/demos/text-fields/

    【讨论】:

    • 好的,谢谢。这些示例是我在本地运行文档时看到的示例。
    • 如果您克隆了 material-ui 存储库,您需要将分支切换到 v1-beta 以获得新版本。
    猜你喜欢
    • 2021-03-04
    • 2021-03-03
    • 1970-01-01
    • 1970-01-01
    • 2018-08-04
    • 2018-09-16
    • 2018-05-10
    • 2019-04-07
    • 2022-08-04
    相关资源
    最近更新 更多