const Demo = (props)=>{
return [
<Foo/>,
<Bar/>
]
}
这样一个组件怎么用typescript重写呢?
尝试写成
interface Props{
}
const Demo:React.FunctionComponent<Props> = (props)=>{}
或者
const Demo:React.ReactElement
或者
const Demo:React.Component
都会报类型错误.
写成下面这种是可以的
const Demo:(props:Props)=>React.ReactNode = (props)=>{
return [
<Foo/>
<Bar/>
]
}
但是这种的在使用Demo组件时又报错
Its return type 'ReactNode' is not a valid JSX element.
我的问题是:如果一个函数式组件返回一个没有rootElement的jsx,用ts应该怎么写?
又自问自答了
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…