JSX element type 'App' is not a constructor function for JSX elements. Types of property 'setState' are incompatible

TLDR; State cannot be null. Declare a interface for it or declare it {}

Answer lies in @types/react

Looking at the definition, neither state nor props are not intended to be null.

When you declared App as class App extends React.Component<{}, null> {, you essentially said, "state is of type null".

Now the type of setState is dependent on the type you specify for state and it clashed with the lesser known version of the setState api. prevState is declared as a {} (the default, since no interface for state was specified) which is not compatible with null, leading to the error log you saw.


Maybe this fix isn't relevant but I got the same error message without having <{}, null> after class App extends React.Component. Here is the fix in my case.

Change import React from 'react';

to import * as React from 'react';