我在我的应用程序中使用打字稿。当使用条件语句返回Component时,我遇到了:
JSX element type 'XXX' does not have any construct or call signatures
const A = () => <div>A</div>
const B = () => <div>B</div>
render(){
const RenderingComponent = someCondition ? A : B
return(
<div>
<RenderingComponent />
</div>
)
}
JSX element type 'RenderingComponent' does not have any construct or call signatures
PS:
我知道我们可以使用最常见的方式来渲染基于条件的组件,例如:<div>
{condition ? <A/> : <B/> }
</div>
我只是想知道如何使它起作用,或者为什么不应该以这种风格编写,谢谢。 :)