Skip to content

Commit 71fd64e

Browse files
committed
context를 이용한 store전달
1 parent 3b07bab commit 71fd64e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

chapter9-1/src/App.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ const ColorList = ({store}) => {
2727

2828

2929
class App extends Component {
30+
getChildContext() {
31+
return {
32+
store : this.props.store
33+
}
34+
}
35+
36+
componentWillMount() {
37+
this.unsubscribe = store.subscribe(()=>this.forceUpdate())
38+
}
39+
40+
componentWillUnmount() {
41+
this.unsubscribe();
42+
}
43+
3044
constructor(props) {
3145
super(props)
3246
this.state = {
@@ -82,4 +96,8 @@ class App extends Component {
8296
}
8397

8498
}
99+
100+
App.childContextTypes = {
101+
store : PropTypes.object.isRequired
102+
}
85103
export default App;

0 commit comments

Comments
 (0)