I worked on my lazy load component's loader and got an error
TS2604: JSX elemy type 'LoadedAsyncComponent' does not have any construct or call signatures
I think so I wrote a bad code and all, because I recently started writing on React + TypeScript chain
and it is my component:
import * as React from 'react';
declare interface AsyncComponentProps {
moduleProvider: Function;
}
declare interface AsyncComponenState {
LoadedAsyncComponent?: (React.Component<any, any> | null);
}
export class AsyncComponent extends React.Component<AsyncComponentProps, AsyncComponenState> {
private isLoaded: boolean = false;
constructor(props: any) {
super(props);
this.state = {
LoadedAsyncComponent: null
};
}
componentWillMount() {
if (!this.isLoaded) {
this.isLoaded = true;
this.props.moduleProvider().then((provideData: any) => {
this.setState({LoadedAsyncComponent: provideData[Object.keys(provideData)[0]] as React.Component});
});
}
}
render() {
const {LoadedAsyncComponent} = this.state;
return LoadedAsyncComponent ? <LoadedAsyncComponent/> : <div className="page-loading">Loading data</div>;
}
}
Error is here:
return LoadedAsyncComponent ? <LoadedAsyncComponent/> : <div className="page-loading">Loading data</div>;
Also moduleProvider
prop is a import promise:
import(/* webpackChunkName: "home" */ './Home/Home')