@@ -90,6 +90,7 @@ I highly recommend to add a bounty to the issue that you're waiting for to incre
90
90
- [ React] ( #react )
91
91
- [ Function Components - FC] ( #function-components---fc )
92
92
- [ - Counter Component] ( #--counter-component )
93
+ - [ - Counter Component with default props] ( #--counter-component-with-default-props )
93
94
- [ - Spreading attributes in Component] ( #--spreading-attributes-in-component )
94
95
- [ Class Components] ( #class-components )
95
96
- [ - Class Counter Component] ( #--class-counter-component )
@@ -325,6 +326,46 @@ export const FCCounter: React.FC<Props> = props => {
325
326
326
327
[⇧ back to top](#table-of-contents)
327
328
329
+ ### - Counter Component with default props
330
+
331
+ ` ` ` tsx
332
+ import * as React from ' react' ;
333
+
334
+ type Props = {
335
+ label: string ;
336
+ count : number ;
337
+ onIncrement : () => void ;
338
+ };
339
+
340
+ // React.FC is unaplicable here due not working properly with default props
341
+ // https://github.com/facebook/create-react-app/pull/8177
342
+ export const FCCounterWithDefaultProps = (props : Props ): JSX .Element => {
343
+ const { label, count, onIncrement } = props ;
344
+
345
+ const handleIncrement = () => {
346
+ onIncrement ();
347
+ };
348
+
349
+ return (
350
+ <div >
351
+ <span >
352
+ { label } : { count }
353
+ </span >
354
+ <button type = " button" onClick = { handleIncrement } >
355
+ { ` Increment ` }
356
+ </button >
357
+ </div >
358
+ );
359
+ };
360
+
361
+ FCCounterWithDefaultProps .defaultProps = { count: 5 };
362
+
363
+ ` ` `
364
+
365
+ [⟩⟩⟩ demo](https://piotrwitek.github.io/react-redux-typescript-guide/#fccounterwithdefaultprops)
366
+
367
+ [⇧ back to top](#table-of-contents)
368
+
328
369
### - [Spreading attributes](https://facebook.github.io/react/docs/jsx-in-depth.html#spread-attributes) in Component
329
370
330
371
` ` ` tsx
0 commit comments