Skip to content

Commit aedd243

Browse files
committed
에러수정
1 parent 71fd64e commit aedd243

File tree

2 files changed

+12
-43
lines changed

2 files changed

+12
-43
lines changed

chapter9-1/src/App.js

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { rateColor, removeColor } from './actions';
99
import { sortFunction } from './lib/array-helpers';
1010

1111

12-
const ColorList = ({store}) => {
12+
const ColorList = (props,{store}) => {
1313
const {colors, sort} = store.getState();
1414
const sortedColors = [...colors].sort(sortFunction(sort));
1515
return (<div className="color-list">
@@ -25,6 +25,10 @@ const ColorList = ({store}) => {
2525
</div>)
2626
}
2727

28+
ColorList.contextTypes = {
29+
store : PropTypes.object
30+
}
31+
2832

2933
class App extends Component {
3034
getChildContext() {
@@ -34,7 +38,7 @@ class App extends Component {
3438
}
3539

3640
componentWillMount() {
37-
this.unsubscribe = store.subscribe(()=>this.forceUpdate())
41+
this.unsubscribe = this.props.store.subscribe(()=>this.forceUpdate())
3842
}
3943

4044
componentWillUnmount() {
@@ -46,55 +50,18 @@ class App extends Component {
4650
this.state = {
4751
colors : []
4852
}
49-
50-
this.addColor = this.addColor.bind(this);
51-
this.rateColor = this.rateColor.bind(this);
52-
this.removeColor = this.removeColor.bind(this);
53+
5354
}
5455
render() {
55-
const { addColor, rateColor, removeColor } = this;
5656
const { colors } = this.state;
57-
const store = this.props.store;
5857
return (
5958
<div className="app">
60-
<SortMenu store={store}/>
61-
<AddColorForm store={store} />
62-
<ColorList store={store} />
59+
<SortMenu />
60+
<AddColorForm />
61+
<ColorList />
6362
</div>
6463
)
6564
}
66-
67-
addColor(title, color) {
68-
const colors = [
69-
...this.state.colors,
70-
{
71-
id : v4(),
72-
title,
73-
color,
74-
rating :0
75-
}
76-
]
77-
this.setState({colors});
78-
}
79-
80-
rateColor(id, rating) {
81-
const colors = this.state.colors.map(color =>
82-
(color.id !== id) ?
83-
color : {
84-
...color,
85-
rating
86-
}
87-
)
88-
this.setState({colors});
89-
}
90-
91-
removeColor(id) {
92-
const colors = this.state.colors.filter(
93-
color => color.id !== id
94-
)
95-
this.setState({colors})
96-
}
97-
9865
}
9966

10067
App.childContextTypes = {

chapter9-1/src/Color.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import PropTypes from 'prop-types';
33
import StarRating from './StarRating';
44
import './Color.css';
55

6+
import { rateColor, removeColor } from './actions';
7+
68
class Color extends Component {
79
constructor(props){
810
super(props);

0 commit comments

Comments
 (0)