File tree Expand file tree Collapse file tree 1 file changed +24
-4
lines changed
packages/react-debug-tools/src Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import type {
12
12
ReactContext ,
13
13
ReactProviderType ,
14
14
StartTransitionOptions ,
15
+ Thenable ,
15
16
Usable ,
16
17
} from 'shared/ReactTypes' ;
17
18
import type {
@@ -122,14 +123,33 @@ function readContext<T>(context: ReactContext<T>): T {
122
123
return context . _currentValue ;
123
124
}
124
125
126
+ function useThenable< T > (thenable: Thenable< T > ): T {
127
+ switch ( thenable . status ) {
128
+ case 'fulfilled' :
129
+ return thenable . value ;
130
+ case 'rejected' :
131
+ throw thenable . reason ;
132
+ case 'pending' :
133
+ default :
134
+ throw thenable ;
135
+ }
136
+ }
137
+
125
138
function use < T > (usable: Usable< T > ): T {
126
139
if ( usable !== null && typeof usable === 'object' ) {
127
140
// $FlowFixMe[method-unbinding]
128
141
if ( typeof usable . then === 'function' ) {
129
- // TODO: What should this do if it receives an unresolved promise?
130
- throw new Error (
131
- 'Support for `use(Promise)` not yet implemented in react-debug-tools.' ,
132
- ) ;
142
+ // This is a thenable.
143
+ const thenable : Thenable < T > = ( usable : any ) ;
144
+ const value = useThenable ( thenable ) ;
145
+
146
+ hookLog . push ( {
147
+ primitive : 'Use' ,
148
+ stackError : new Error ( ) ,
149
+ value,
150
+ } ) ;
151
+
152
+ return value ;
133
153
} else if (usable.$$typeof === REACT_CONTEXT_TYPE) {
134
154
const context : ReactContext < T > = ( usable : any ) ;
135
155
const value = readContext ( context ) ;
You can’t perform that action at this time.
0 commit comments