Skip to content

Commit 40edfc6

Browse files
committed
react-redux coonect사용하기
1 parent 5aee20e commit 40edfc6

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

chapter9-4/src/containers.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,24 @@ import ColorList from './App';
99
import { rateColor, removeColor, addColor, sortColors } from './actions';
1010
import { sortFunction } from './lib/array-helpers';
1111

12-
export const NewColor = (props, {store}) =>
13-
<AddColorForm onNewColor={(title, color) => store.dispatch(addColor(title, color))} />
14-
15-
NewColor.contextTypes = {
16-
store : PropTypes.object
17-
}
18-
export const Menu = (props, {store}) =>
19-
<SortMenu sort={store.getState().sort} onSelect={sortBy => store.dispatch(sortColors(sortBy))} />
12+
export const NewColor = connect(
13+
null,
14+
dispatch =>
15+
({
16+
onNewColor(title, color) {
17+
dispatch(addColor(title, color));
18+
}
19+
})(AddColorForm)
20+
)
2021

22+
export const Menu = connect(
23+
null,
24+
({
25+
onSelect(sortBy) {
26+
dispatch(sortColors(sortBy))
27+
}
28+
})(sortMenu)
29+
)
2130
Menu.contextTypes = {
2231
store : PropTypes.object
2332
}

0 commit comments

Comments
 (0)