首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >排版组件

排版组件
EN

Stack Overflow用户
提问于 2019-10-08 05:57:51
回答 2查看 719关注 0票数 3

根据此处的材料ui文档:https://material-ui.com/components/typography/

我应该能够像下面这样使用排版组件:

代码语言:javascript
复制
<Typography variant="h1" component="h1">
  Hello World
</Typography>

然而,由于更新到了nextjs 9,我得到了这样的输入错误:

代码语言:javascript
复制
Type 'string' is not assignable to type 'ElementType<HTMLAttributes<HTMLElement>>'

用于零部件特性。我已经尝试过多次更新类型依赖项,但似乎没有任何帮助。

多亏了沙农的建议,错误现在已经转移到:

代码语言:javascript
复制
48:36 Type '"h1"' is not assignable to type 'ElementType<HTMLAttributes<HTMLElement>>'.
    46 |         </Grid>
    47 |         <Grid item>
  > 48 |           <Typography variant="h1" component={'h1' as const}>
       |                                    ^
    49 |             Hello World
    50 |           </Typography>
    51 |         </Grid>

这对我来说仍然是个拦路虎。

考虑到我给出的第一个例子与文档完全匹配,我对如何进行这个主题感到困惑。

EN

回答 2

Stack Overflow用户

发布于 2019-10-09 04:25:07

ComponentType是React的未初始化形式的功能组件/类组件的类型。

也就是说,为了满足需要"React.ComponentType“的东西,你可以简单地这样做……

代码语言:javascript
复制
const test: React.ComponentType<{name: string}> = ({name})  => <div>I AM DIV</div>;
const test1: React.ComponentType<{name: string}> = class extends React.Component<{name: string}> { render() {return <div>I AM DIV TO</div>}};
票数 0
EN

Stack Overflow用户

发布于 2019-11-12 20:21:40

就隐藏打字错误而言,使用component={'div' as any}对我很有效。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58277659

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档