File tree 1 file changed +14
-3
lines changed
1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -22,19 +22,25 @@ class Main extends Component{
22
22
}
23
23
24
24
class Title extends Component {
25
+ static contextTypes = {
26
+ color : PropTypes . string
27
+ }
25
28
render ( ) {
26
29
return (
27
- < div >
30
+ < div style = { { color : this . context . color } } >
28
31
这里是标题部分
29
32
</ div >
30
33
)
31
34
}
32
35
}
33
36
34
37
class Content extends Component {
38
+ static contextTypes = {
39
+ color : PropTypes . string
40
+ }
35
41
render ( ) {
36
42
return (
37
- < div >
43
+ < div style = { { color : this . context . color } } >
38
44
这里是内容部分
39
45
</ div >
40
46
)
@@ -43,14 +49,19 @@ class Content extends Component{
43
49
44
50
class HomePage extends Component {
45
51
static childContextTypes = {
46
- color : PropTypes . string
52
+ color : PropTypes . string
47
53
}
48
54
constructor ( props ) {
49
55
super ( props ) ;
50
56
this . state = {
51
57
color : 'red'
52
58
}
53
59
}
60
+ getChildContext ( ) {
61
+ return {
62
+ color : this . state . color
63
+ }
64
+ }
54
65
render ( ) {
55
66
return (
56
67
< div >
You can’t perform that action at this time.
0 commit comments