@@ -99,48 +99,48 @@ npm i -D @types/react @types/react-dom @types/react-redux
9999#### ` React.FunctionComponent<P> ` or ` React.FC<P> `
100100Type representing a functional component
101101``` tsx
102- const MyComponent: React .FC <MyComponentProps > = ...
102+ const MyComponent: React .FC <Props > = ...
103103```
104- [ ⇧ back to top] ( #table-of-contents )
105104
106105#### ` React.Component<P, S> `
107106Type representing a class component
108107``` 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 > ;
110115` ` `
111- [⇧ back to top](#table-of-contents)
112116
113117#### ` React .ComponentType <P >`
114- Type representing union type of (FC | Component)
118+ Type representing union type of (React. FC | React. Component)
115119` ` ` tsx
116120const withState = <P extends WrappedComponentProps >(
117121 WrappedComponent : React .ComponentType <P >,
118122) => { ...
119123` ` `
120- [⇧ back to top](#table-of-contents)
121124
122125#### ` React .ReactElement <P >` or ` JSX .Element `
123126Type representing a concept of React Element - representation of a native DOM component (e.g. ` < div / > ` ), or a user-defined composite component (e.g. ` < MyComponent / > ` )
124127` ` ` tsx
125128const elementOnly: React .ReactElement = <div /> || <MyComponent />;
126129` ` `
127- [⇧ back to top](#table-of-contents)
128130
129131#### ` React .ReactNode `
130132Type representing any possible type of React node (basically ReactElement (including Fragments and Portals) + primitive JS types)
131133` ` ` tsx
132134const elementOrPrimitive: React .ReactNode = ' string' || 0 || false || null || undefined || <div /> || <MyComponent />;
133135const Component = ({ children : React .ReactNode }) => ...
134136` ` `
135- [⇧ back to top](#table-of-contents)
136137
137138#### ` React .CSSProperties `
138139Type representing style object in JSX (usefull for css-in-js styles)
139140` ` ` tsx
140141const styles: React .CSSProperties = { flexDirection: ' row' , ...
141142const element = <div style = { styles } ...
142143```
143- [⇧ back to top](#table-of-contents)
144144
145145#### `React.ReactEventHandler<E>`
146146Type representing generic event handler
@@ -149,7 +149,6 @@ const handleChange: React.ReactEventHandler<HTMLInputElement> = (ev) => { ... }
149149
150150<input onChange = { handleChange } ... />
151151` ` `
152- [⇧ back to top](#table-of-contents)
153152
154153#### ` React .MouseEvent <E >` | ` React .KeyboardEvent <E >` | ` React .TouchEvent <E >` etc...
155154Type representing more specific event handler
@@ -158,6 +157,7 @@ const handleChange = (ev: React.MouseEvent<HTMLDivElement>) => { ... }
158157
159158<div onMouseMove = { handleChange } ... />
160159` ` `
160+
161161[⇧ back to top](#table-of-contents)
162162
163163---
0 commit comments