What does the error “JSX element type '…' does not have any construct or call signatures” mean?

后端 未结 13 2314
余生分开走
余生分开走 2020-11-28 02:05

I wrote some code:

function renderGreeting(Elem: React.Component) {
    return Hello, !;
}
         


        
13条回答
  •  生来不讨喜
    2020-11-28 02:45

    If you are using material-ui, go to type definition of the component, which is being underlined by TypeScript. Most likely you will see something like this

    export { default } from './ComponentName';
    

    You have 2 options to resolve the error:

    1.Add .default when using the component in JSX:

    import ComponentName from './ComponentName'
    
    const Component = () => 
    

    2.Rename the component, which is being exported as "default", when importing:

    import { default as ComponentName } from './ComponentName'
    
    const Component = () => 
    

    This way you don't need to specify .default every time you use the component.

提交回复
热议问题