React And Typescript
Edit page
HomeTypeScript Crash Course
Installation
Examples
ContributingReadme

Class Components

React.Component is used to describe a class component. React.Component is a generic type that takes two optional type variables, PropType and StateType.

The following example is from the react-typescript-cheatsheet.

type MyProps = {
// using `interface` is also ok
message: string;
};
type MyState = {
count: number; // like this
};
class App extends React.Component<MyProps, MyState> {
state: MyState = {
// optional second annotation for better type inference
count: 0,
};
render() {
return (
<div>
{this.props.message} {this.state.count}
</div>
);
}
}

This video explains another example of typing a class component.