File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
typescript-react-starter/src Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -3,9 +3,11 @@ import * as React from 'react';
3
3
export interface Props {
4
4
name : string ;
5
5
enthusiasmLevel ?: number ;
6
+ onIncrement ?: ( ) => void ;
7
+ onDecrement ?: ( ) => void ;
6
8
}
7
9
8
- function Hello ( { name, enthusiasmLevel = 1 } : Props ) {
10
+ function Hello ( { name, enthusiasmLevel = 1 , onIncrement , onDecrement } : Props ) {
9
11
if ( enthusiasmLevel <= 0 ) {
10
12
throw new Error ( 'You could be a little more enthusiastic. :D' ) ;
11
13
}
@@ -15,6 +17,10 @@ function Hello({ name, enthusiasmLevel = 1}: Props) {
15
17
< div className = "greeting" >
16
18
Hello { name + getExclamationMarks ( enthusiasmLevel ) }
17
19
</ div >
20
+ < div >
21
+ < button onClick = { onDecrement } > -</ button >
22
+ < button onClick = { onIncrement } > +</ button >
23
+ </ div >
18
24
</ div >
19
25
) ;
20
26
}
Original file line number Diff line number Diff line change
1
+ import { connect } from 'react-redux' ;
2
+ import { Dispatch } from 'redux' ;
3
+
4
+ import Hello from '../components/Hello'
5
+ import * as actions from '../actions'
6
+ import { StoreState } from '../types' ;
7
+
8
+ export function mapStateToProps ( { enthusiamLevel, languageName } : StoreState ) {
9
+ return {
10
+ enthusiamLevel,
11
+ name : languageName ,
12
+ } ;
13
+ }
14
+
15
+ export function mapDispatchToProps ( dispatch : Dispatch < actions . EnthusiasmAction > ) {
16
+ return {
17
+ onIncrement : ( ) => dispatch ( actions . incrementEnthusiasm ( ) ) ,
18
+ onDecrement : ( ) => dispatch ( actions . decrementEnthusiasm ( ) ) ,
19
+ } ;
20
+ }
21
+
22
+ export default connect ( mapStateToProps , mapDispatchToProps ) ( Hello ) ;
You can’t perform that action at this time.
0 commit comments