jsx元素类型xx没有任何构造或调用签名

时间:2019-07-08 06:04:11

标签: reactjs typescript

我在我的应用程序中使用打字稿。当使用条件语句返回Component时,我遇到了: JSX element type 'XXX' does not have any construct or call signatures

  1. 我有2个组件,分别为A和B。
const A = () => <div>A</div>
const B = () => <div>B</div>
  1. 我想根据条件渲染其中之一,因此我的代码如下:
render(){
  const RenderingComponent = someCondition ? A : B  
  return(
    <div>
       <RenderingComponent />
    </div>
  )
}
  1. VSCode向我显示错误:JSX element type 'RenderingComponent' does not have any construct or call signatures PS: 我知道我们可以使用最常见的方式来渲染基于条件的组件,例如:
<div>
{condition ? <A/> : <B/> }
</div>

我只是想知道如何使它起作用,或者为什么不应该以这种风格编写,谢谢。 :)

0 个答案:

没有答案