Skip to content

Commit 9ffec00

Browse files
committed
Making a container
1 parent 4dbc4e0 commit 9ffec00

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

typescript-react-starter/src/components/Hello.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import * as React from 'react';
33
export interface Props {
44
name: string;
55
enthusiasmLevel?: number;
6+
onIncrement?: () => void;
7+
onDecrement?: () => void;
68
}
79

8-
function Hello({ name, enthusiasmLevel = 1}: Props) {
10+
function Hello({ name, enthusiasmLevel = 1, onIncrement, onDecrement }: Props) {
911
if (enthusiasmLevel <= 0) {
1012
throw new Error('You could be a little more enthusiastic. :D');
1113
}
@@ -15,6 +17,10 @@ function Hello({ name, enthusiasmLevel = 1}: Props) {
1517
<div className="greeting">
1618
Hello {name + getExclamationMarks(enthusiasmLevel)}
1719
</div>
20+
<div>
21+
<button onClick={onDecrement}>-</button>
22+
<button onClick={onIncrement}>+</button>
23+
</div>
1824
</div>
1925
);
2026
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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);

0 commit comments

Comments
 (0)