@@ -99,48 +99,48 @@ npm i -D @types/react @types/react-dom @types/react-redux
99
99
#### ` React.FunctionComponent<P> ` or ` React.FC<P> `
100
100
Type representing a functional component
101
101
``` tsx
102
- const MyComponent: React .FC <MyComponentProps > = ...
102
+ const MyComponent: React .FC <Props > = ...
103
103
```
104
- [ ⇧ back to top] ( #table-of-contents )
105
104
106
105
#### ` React.Component<P, S> `
107
106
Type representing a class component
108
107
``` tsx
109
- class MyComponent extends React .Component <MyComponentProps , State > { ...
108
+ class MyComponent extends React .Component <Props , State > { ...
109
+ ` ` `
110
+
111
+ #### ` React .ComponentProps <typeof Component >`
112
+ Gets type of Component Props, so you don't need to export Props from your component ever! (Works for both FC and Class components)
113
+ ` ` ` tsx
114
+ type MyComponentProps = React .ComponentProps < typeof MyComponent > ;
110
115
` ` `
111
- [⇧ back to top](#table-of-contents)
112
116
113
117
#### ` React .ComponentType <P >`
114
- Type representing union type of (FC | Component)
118
+ Type representing union type of (React. FC | React. Component)
115
119
` ` ` tsx
116
120
const withState = <P extends WrappedComponentProps >(
117
121
WrappedComponent : React .ComponentType <P >,
118
122
) => { ...
119
123
` ` `
120
- [⇧ back to top](#table-of-contents)
121
124
122
125
#### ` React .ReactElement <P >` or ` JSX .Element `
123
126
Type representing a concept of React Element - representation of a native DOM component (e.g. ` < div / > ` ), or a user-defined composite component (e.g. ` < MyComponent / > ` )
124
127
` ` ` tsx
125
128
const elementOnly: React .ReactElement = <div /> || <MyComponent />;
126
129
` ` `
127
- [⇧ back to top](#table-of-contents)
128
130
129
131
#### ` React .ReactNode `
130
132
Type representing any possible type of React node (basically ReactElement (including Fragments and Portals) + primitive JS types)
131
133
` ` ` tsx
132
134
const elementOrPrimitive: React .ReactNode = ' string' || 0 || false || null || undefined || <div /> || <MyComponent />;
133
135
const Component = ({ children : React .ReactNode }) => ...
134
136
` ` `
135
- [⇧ back to top](#table-of-contents)
136
137
137
138
#### ` React .CSSProperties `
138
139
Type representing style object in JSX (usefull for css-in-js styles)
139
140
` ` ` tsx
140
141
const styles: React .CSSProperties = { flexDirection: ' row' , ...
141
142
const element = <div style = { styles } ...
142
143
```
143
- [⇧ back to top](#table-of-contents)
144
144
145
145
#### `React.ReactEventHandler<E>`
146
146
Type representing generic event handler
@@ -149,7 +149,6 @@ const handleChange: React.ReactEventHandler<HTMLInputElement> = (ev) => { ... }
149
149
150
150
<input onChange = { handleChange } ... />
151
151
` ` `
152
- [⇧ back to top](#table-of-contents)
153
152
154
153
#### ` React .MouseEvent <E >` | ` React .KeyboardEvent <E >` | ` React .TouchEvent <E >` etc...
155
154
Type representing more specific event handler
@@ -158,6 +157,7 @@ const handleChange = (ev: React.MouseEvent<HTMLDivElement>) => { ... }
158
157
159
158
<div onMouseMove = { handleChange } ... />
160
159
` ` `
160
+
161
161
[⇧ back to top](#table-of-contents)
162
162
163
163
---
0 commit comments