File tree 1 file changed +24
-13
lines changed
packages/react-devtools-shared/src/devtools
1 file changed +24
-13
lines changed Original file line number Diff line number Diff line change @@ -59,19 +59,30 @@ const Pending = 0;
59
59
const Resolved = 1 ;
60
60
const Rejected = 2 ;
61
61
62
- const ReactSharedInternals = ( React : any )
63
- . __CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE ;
64
-
65
- function readContext ( Context : ReactContext < null > ) {
66
- const dispatcher = ReactSharedInternals . H ;
67
- if ( dispatcher === null ) {
68
- throw new Error (
69
- 'react-cache: read and preload may only be called from within a ' +
70
- "component's render. They are not supported in event handlers or " +
71
- 'lifecycle methods.' ,
72
- ) ;
73
- }
74
- return dispatcher . readContext ( Context ) ;
62
+ let readContext ;
63
+ if ( typeof React . use === 'function' ) {
64
+ readContext = function ( Context : ReactContext < null > ) {
65
+ return React . use ( Context ) ;
66
+ } ;
67
+ } else if (
68
+ typeof ( React : any ) . __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED ===
69
+ 'object'
70
+ ) {
71
+ const ReactCurrentDispatcher = ( React : any )
72
+ . __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED . ReactCurrentDispatcher ;
73
+ readContext = function ( Context : ReactContext < null > ) {
74
+ const dispatcher = ReactCurrentDispatcher . current ;
75
+ if ( dispatcher === null ) {
76
+ throw new Error (
77
+ 'react-cache: read and preload may only be called from within a ' +
78
+ "component's render. They are not supported in event handlers or " +
79
+ 'lifecycle methods.' ,
80
+ ) ;
81
+ }
82
+ return dispatcher . readContext ( Context ) ;
83
+ } ;
84
+ } else {
85
+ throw new Error ( 'react-cache: Unsupported React version' ) ;
75
86
}
76
87
77
88
const CacheContext = createContext ( null ) ;
You can’t perform that action at this time.
0 commit comments