I am wondering how to pass JSX (like "div" or "span") or React components to my own component. So, I tried to work with React.ReactType to support both. My Code looks like the following:
LazySvgIcon.tsx
import * as React from 'react'
interface Props {
src: string
loading?: React.ReactType
error?: React.ReactType
}
interface State {
isLoading: boolean,
hasError: boolean
}
export const LazySvgIcon =
class LazySvgIcon extends React.Component<Props, State> {
constructor(props: Props, context?: any) {
super(props, context)
this.state = {
isLoading: false,
hasError: false
}
}
render() {
const { isLoading, hasError } = this.state
const { loading:Loader, error:Error } = this.props
return(
<React.Fragment>
{ isLoading && Loader && <Loader /> }
{ hasError && Error && <Error /> }
</React.Fragment>
)
}
}
However I get the error for my Loader and Error component that...
[ts] JSX element type 'Loader' does not have any construct or call signatures. [2604]
When I change ReactType to ComponentType, the code is working, but this is not what I want, because then I can't pass a <div> container for instance.
What's the correct way to use React.ReactType with TypeScript in *.tsx files?
Versions in use: TypeScript 3.2.4, React 16.7.0