【发布时间】:2020-08-12 10:40:35
【问题描述】:
我正在创建一个<Text /> 组件,以便我可以轻松控制文本在我的应用程序中的使用方式。我希望能够为<Text /> 组件选择一个标签,具体取决于它是什么(例如<p> 用于正文,<h1> 用于标题)。
但是,我被困在了第一步。当我尝试使用函数返回标签时,出现以下错误:
Type '{ children: string; }' has no properties in common with type 'IntrinsicAttributes'.ts(2559)
这是我的组件:
import * as React from 'react'
export class Text extends React.Component {
constructor(props) {
super(props)
}
getMarkup() {
return 'h1'
}
render() {
const CustomTag = this.getMarkup()
return (<CustomTag>Hello</CustomTag>)
}
}
【问题讨论】:
-
这是在没有打字稿的反应应用程序中工作吗?你检查过一次吗?
-
你能添加沙箱复制错误吗?
标签: javascript reactjs typescript jsx