| 747 | } |
| 748 | |
| 749 | function use<T>(usable: Usable<T>): T { |
| 750 | if (usable !== null && typeof usable === 'object') { |
| 751 | // $FlowFixMe[method-unbinding] |
| 752 | if (typeof usable.then === 'function') { |
| 753 | // This is a thenable. |
| 754 | const thenable: Thenable<T> = (usable: any); |
| 755 | return unwrapThenable(thenable); |
| 756 | } else if (usable.$$typeof === REACT_CONTEXT_TYPE) { |
| 757 | const context: ReactContext<T> = (usable: any); |
| 758 | return readContext(context); |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | // eslint-disable-next-line react-internal/safe-string-coercion |
| 763 | throw new Error('An unsupported type was passed to use(): ' + String(usable)); |
| 764 | } |
| 765 | |
| 766 | export function unwrapThenable<T>(thenable: Thenable<T>): T { |
| 767 | const index = thenableIndexCounter; |