MCPcopy
hub / github.com/facebook/react / use

Function use

packages/react-server/src/ReactFizzHooks.js:749–764  ·  view source on GitHub ↗
(usable: Usable<T>)

Source from the content-addressed store, hash-verified

747}
748
749function 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
766export function unwrapThenable<T>(thenable: Thenable<T>): T {
767 const index = thenableIndexCounter;

Callers 15

ComponentFunction · 0.90
OutputContentFunction · 0.90
ContentFunction · 0.90
ShellFunction · 0.90
UseFunction · 0.90
PrintFunction · 0.50
ClientRootFunction · 0.50
PageFunction · 0.50
AppFunction · 0.50
ComponentFunction · 0.50

Calls 2

readContextFunction · 0.90
unwrapThenableFunction · 0.70

Tested by 15

ComponentFunction · 0.72
PrintFunction · 0.40
ClientRootFunction · 0.40
PageFunction · 0.40
AppFunction · 0.40
ComponentFunction · 0.40
AwaitFunction · 0.40
ClientAppFunction · 0.40
ClientRootFunction · 0.40
ClientRootFunction · 0.40
AppFunction · 0.40
ClientFunction · 0.40