Skip to content

Commit 4dccab9

Browse files
authored
Update README.md
1 parent 3f72c9d commit 4dccab9

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

README.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ Set of guidelines and patterns teaching how to fully leverage TypeScript feature
1919
- [Actions](#actions)
2020
- [Reducers](#reducers)
2121
- [Async Flow](#async-flow)
22+
- [Reselect Selectors](#reselect-selectors)
2223
- [Store & RootState](#store--rootstate)
23-
- [Types Selectors](#typed-selectors)
2424
- [Common](#common)
2525
- [Vendor Types Augumentation](#vendor-types-augmentation)
2626
- [FAQ](#faq)
@@ -33,6 +33,8 @@ Set of guidelines and patterns teaching how to fully leverage TypeScript feature
3333
- Don't use constructor - use Property Initializers
3434
- Don't use instance methods and bind - use Class Fields with arrow functions
3535

36+
---
37+
3638
## Class Component
3739
- class component boilerplate
3840
```tsx
@@ -84,8 +86,11 @@ class MyComponent extends React.Component<Props, State> {
8486
};
8587

8688
export default MyComponent;
89+
8790
```
8891

92+
---
93+
8994
## Stateless Component
9095
- stateless component boilerplate
9196
```tsx
@@ -109,8 +114,11 @@ const MyComponent: React.StatelessComponent<Props> = (props) => {
109114
};
110115

111116
export default MyComponent;
117+
112118
```
113119

120+
---
121+
114122
## Higher-Order Component
115123
- decorate or wraps a component into another component
116124
- using Type Inference to automatically calculate Props interface for the resulting component
@@ -142,6 +150,7 @@ const ButtonControl: React.StatelessComponent<Props> = (props) => {
142150
};
143151

144152
export default ButtonControl;
153+
145154
```
146155

147156
```tsx
@@ -193,8 +202,11 @@ const ButtonWithFormItem = withFormItemDecorator(Button);
193202
Next Step
194203
</ButtonWithFormItem>
195204
...
205+
196206
```
197207

208+
---
209+
198210
## Redux Connected Component
199211
- This solution uses type inference to get Props types from `mapStateToProps` function
200212
- Minimise manual effort to declare and maintain Props types injected from `connect` helper function
@@ -259,12 +271,16 @@ class CurrencyConverterContainer extends React.Component<Props, State> {
259271
}
260272

261273
export default connect(mapStateToProps, dispatchToProps)(CurrencyConverterContainer);
274+
262275
```
263276

277+
264278
---
265279

266280
# Redux
267281

282+
---
283+
268284
## Actions
269285

270286
### KISS Approach
@@ -311,6 +327,7 @@ export default function reducer(state: State = initialState, action: Action): St
311327
state.baseCurrency = action.payload // string
312328
break;
313329
...
330+
314331
```
315332
316333
### DRY Approach
@@ -346,6 +363,7 @@ export default function reducer(state: State = initialState, action: Action): St
346363
state.baseCurrency = action.payload; // string
347364
}
348365
...
366+
349367
```
350368
351369
---
@@ -383,6 +401,7 @@ export default function reducer(state: State = initialState, action: Action): St
383401
default: return state;
384402
}
385403
}
404+
386405
```
387406
388407
### If Approach
@@ -412,6 +431,7 @@ export default function reducer(state: State = initialState, action: Action): St
412431

413432
return partialState != null ? { ...state, ...partialState } : state;
414433
}
434+
415435
```
416436
417437
---
@@ -425,6 +445,15 @@ export default function reducer(state: State = initialState, action: Action): St
425445
426446
---
427447
448+
## Reselect Selectors
449+
- WIP
450+
451+
```ts
452+
453+
```
454+
455+
---
456+
428457
## Store & RootState
429458
430459
`RootState` - to be imported in connected components providing type safety to Redux `connect` function
@@ -440,6 +469,7 @@ export type RootState = {
440469
currencyRates: CurrencyRatesState;
441470
currencyConverter: CurrencyConverterState;
442471
};
472+
443473
```
444474
445475
Use `RootState` in `combineReducers` function and as rehydrated State object type guard to obtain strongly typed Store instance
@@ -458,12 +488,8 @@ export const store = createStore(
458488
rootReducer,
459489
recoverState(),
460490
);
461-
```
462-
463-
---
464491

465-
## Typed Selectors
466-
- WIP
492+
```
467493
468494
---
469495
@@ -484,6 +510,7 @@ declare module '../node_modules/antd/lib/button/Button' {
484510
autoFocus?: boolean;
485511
}
486512
}
513+
487514
```
488515
489516
---
@@ -517,6 +544,7 @@ import { Select } from '../components';
517544
or
518545
import Select from '../components/select';
519546
...
547+
520548
```
521549
522550
---

0 commit comments

Comments
 (0)