@@ -109,16 +109,20 @@ npm i -D @types/react @types/react-dom @types/react-redux
109
109
#### ` React.FunctionComponent<P> ` or ` React.FC<P> `
110
110
Type representing a functional component
111
111
``` tsx
112
- const MyComponent: React .FC <MyComponentProps > = ...
112
+ const MyComponent: React .FC <Props > = ...
113
113
```
114
- [ ⇧ back to top] ( #table-of-contents )
115
114
116
115
#### ` React.Component<P, S> `
117
116
Type representing a class component
118
117
``` tsx
119
- class MyComponent extends React .Component <MyComponentProps , State > { ...
118
+ class MyComponent extends React .Component <Props , State > { ...
119
+ ` ` `
120
+
121
+ #### ` React .ComponentProps < typeof Component >
122
+ Gets component Props type . You don ' t no need to export Props from your component ever!
123
+ ` ` ` tsx
124
+ type MyComponentProps = React.ComponentProps<typeof MyComponent>;
120
125
` ` `
121
- [⇧ back to top](#table-of-contents)
122
126
123
127
#### ` React.ComponentType<P> `
124
128
Type representing union type of (FC | Component )
@@ -127,30 +131,26 @@ const withState = <P extends WrappedComponentProps>(
127
131
WrappedComponent: React.ComponentType<P>,
128
132
) => { ...
129
133
` ` `
130
- [⇧ back to top](#table-of-contents)
131
134
132
135
#### ` React.ReactElement<P> ` or ` JSX.Element `
133
136
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 /> ` )
134
137
` ` ` tsx
135
138
const elementOnly: React.ReactElement = <div /> || <MyComponent />;
136
139
` ` `
137
- [⇧ back to top](#table-of-contents)
138
140
139
141
#### ` React.ReactNode `
140
142
Type representing any possible type of React node (basically ReactElement (including Fragments and Portals ) + primitive JS types)
141
143
` ` ` tsx
142
144
const elementOrPrimitive: React.ReactNode = 'string' || 0 || false || null || undefined || <div /> || <MyComponent />;
143
145
const Component = ({ children: React.ReactNode }) => ...
144
146
` ` `
145
- [⇧ back to top](#table-of-contents)
146
147
147
148
#### ` React.CSSProperties `
148
149
Type representing style object in JSX (usefull for css -in -js styles )
149
150
` ` ` tsx
150
151
const styles: React.CSSProperties = { flexDirection: 'row', ...
151
152
const element = <div style={styles} ...
152
153
` ` `
153
- [⇧ back to top](#table-of-contents)
154
154
155
155
#### ` React.ReactEventHandler<E> `
156
156
Type representing generic event handler
@@ -159,7 +159,6 @@ const handleChange: React.ReactEventHandler<HTMLInputElement> = (ev) => { ... }
159
159
160
160
<input onChange={handleChange} ... />
161
161
` ` `
162
- [⇧ back to top](#table-of-contents)
163
162
164
163
#### ` React.MouseEvent<E> ` | ` React.KeyboardEvent<E> ` | ` React.TouchEvent<E> ` etc ...
165
164
Type representing more specific event handler
@@ -168,6 +167,7 @@ const handleChange = (ev: React.MouseEvent<HTMLDivElement>) => { ... }
168
167
169
168
<div onMouseMove={handleChange} ... />
170
169
` ` `
170
+
171
171
[⇧ back to top ](#table -of -contents )
172
172
173
173
-- -
0 commit comments