Categories
TypeScript Answers

How to fix the ‘What does the error “JSX element type ‘…’ does not have any construct or call signatures”‘ error with TypeScript and React?

Spread the love

To fix the ‘What does the error "JSX element type ‘…’ does not have any construct or call signatures"’ error with TypeScript and React, we should use new to instantiate React component classes.

For instance, we shouldn’t write

class Greeter extends React.Component<any, any> {
  render() {
    return <div>Hello, {this.props.name}</div>;
  }
}

//...
const Greet = new Greeter();
<Greet whoToGreet="world" />;

Instead, we write

class Greeter extends React.Component<any, any> {
  render() {
    return <div>Hello, {this.props.name}</div>;
  }
}

//...
<Greet whoToGreet="world" />;

to use the Greet component after we defined it.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.