Skip to content

Commit eafebe4

Browse files
authored
Merge pull request #9 from AryanJ-NYC/feature/8
Add class component page
2 parents 77b7f97 + b59725b commit eafebe4

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
name: Class Components
3+
route: /examples/class-components
4+
menu: Examples
5+
---
6+
7+
import SEO from '../../components/Seo';
8+
9+
<SEO
10+
description="Using TypeScript with React class components."
11+
title="Class Components"
12+
keywords={['class components']}
13+
/>
14+
15+
# Class Components
16+
17+
`React.Component` is used to describe a class component. `React.Component` is a generic type that takes two **_optional_** type variables, `PropType` and `StateType`.
18+
19+
The following example is from the [react-typescript-cheatsheet](https://github.com/typescript-cheatsheets/react-typescript-cheatsheet).
20+
21+
```typescript
22+
type MyProps = {
23+
// using `interface` is also ok
24+
message: string;
25+
};
26+
type MyState = {
27+
count: number; // like this
28+
};
29+
class App extends React.Component<MyProps, MyState> {
30+
state: MyState = {
31+
// optional second annotation for better type inference
32+
count: 0,
33+
};
34+
render() {
35+
return (
36+
<div>
37+
{this.props.message} {this.state.count}
38+
</div>
39+
);
40+
}
41+
}
42+
```

src/pages/examples/hocs.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ menu: Examples
77
import SEO from '../../components/Seo';
88

99
<SEO
10-
description="Using TypeScript with higher order components or HOCs."
10+
description="Using TypeScript with higher order components or HOCs in React."
1111
title="Higher Order Components (HOCs)"
1212
keywords={['higher-order components', 'higher order components', 'hocs']}
1313
/>

src/pages/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ Visit the [GitHub repository](https://github.com/AryanJ-NYC/reactandtypescript.d
1919

2020
For questions that are not covered in the documentation or to chat about React + TypeScript, join our [Spectrum Chat](https://spectrum.chat/react-and-typescript).
2121

22-
A special thank you to [@swyx](https://twitter.com/swyx)'s [React TypeScript cheatsheet](https://github.com/sw-yx/react-typescript-cheatsheet).
22+
A special thank you to [@swyx](https://twitter.com/swyx) for starting the [React TypeScript cheatsheet](https://github.com/typescript-cheatsheets/react-typescript-cheatsheet) and inspiring the existence of this website.
2323

2424
Lastly, tweet me at [@AryanJabbari](https://twitter.com/AryanJabbari). Words of encouragement are always welcome!

0 commit comments

Comments
 (0)