1313
1414const React = require ( 'react' ) ;
1515const ReactDOM = require ( 'react-dom' ) ;
16+ const PropTypes = require ( 'prop-types' ) ;
1617const ScheduleTracing = require ( 'scheduler/tracing' ) ;
1718const Immutable = require ( 'immutable' ) ;
1819const assign = require ( 'object-assign' ) ;
@@ -37,6 +38,8 @@ const themes = {
3738const ThemeContext = React . createContext ( ) ;
3839ThemeContext . displayName = 'ThemeContext' ;
3940
41+ const LocaleContext = React . createContext ( 'en-US' ) ;
42+
4043class Todos extends React . Component {
4144 ref = React . createRef ( ) ;
4245
@@ -48,17 +51,6 @@ class Todos extends React.Component {
4851 { title : 'Inspect all the things' , completed : true , id : 10 } ,
4952 { title : 'Profit!!' , completed : false , id : 11 } ,
5053 { title : 'Profit!!' , completed : false , id : 12 } ,
51- /*
52- {title: 'Profit!!', completed: false, id: 13},
53- {title: 'Profit!!', completed: false, id: 14},
54- {title: 'Profit!!', completed: false, id: 15},
55- {title: 'Profit!!', completed: false, id: 16},
56- {title: 'Profit!!', completed: false, id: 17},
57- {title: 'Profit!!', completed: false, id: 18},
58- {title: 'Profit!!', completed: false, id: 19},
59- {title: 'Profit!!', completed: false, id: 21},
60- {title: 'Profit!!', completed: false, id: 41},
61- */
6254 ] ,
6355 filter : 'All' ,
6456 } ;
@@ -480,6 +472,12 @@ class Wrap extends React.Component {
480472 <span val={null}/>
481473 <span val={undefined}/>
482474 <div><</div>*/ }
475+ < div style = { styles . container } >
476+ Context tests
477+ < SimpleContextType />
478+ < ObjectContextType />
479+ < LegacyContextTypes />
480+ </ div >
483481 < DeeplyNested />
484482 < PropTester awesome = { 2 } />
485483 < PropTester { ...emptyProps } />
@@ -553,6 +551,62 @@ function long(children) { // eslint-disable-line no-unused-vars
553551 ) ;
554552}
555553
554+ class SimpleContextType extends React . Component {
555+ static contextType = LocaleContext ;
556+
557+ render ( ) {
558+ return (
559+ < div >
560+ Simple: { this . context }
561+ </ div >
562+ ) ;
563+ }
564+ }
565+
566+ class ObjectContextType extends React . Component {
567+ static contextType = ThemeContext ;
568+
569+ render ( ) {
570+ return (
571+ < div >
572+ Object: { this . context . primary } , { this . context . contrast }
573+ </ div >
574+ ) ;
575+ }
576+ }
577+
578+ class LegacyContextTypes extends React . Component {
579+ static childContextTypes = {
580+ locale : PropTypes . string ,
581+ theme : PropTypes . object ,
582+ } ;
583+
584+ getChildContext ( ) {
585+ return {
586+ locale : 'en-US' ,
587+ theme : themes . blue ,
588+ } ;
589+ }
590+
591+ render ( ) {
592+ return < LegacyContextTypesConsumer /> ;
593+ }
594+ }
595+ class LegacyContextTypesConsumer extends React . Component {
596+ static contextTypes = {
597+ locale : PropTypes . string ,
598+ theme : PropTypes . object ,
599+ } ;
600+
601+ render ( ) {
602+ return (
603+ < div >
604+ Legacy: { this . context . locale } , { this . context . theme . primary } , { this . context . theme . contrast }
605+ </ div >
606+ ) ;
607+ }
608+ }
609+
556610class Target extends React . Component {
557611 constructor ( props ) {
558612 super ( props ) ;
0 commit comments