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

Function useSyncExternalStore

packages/react-debug-tools/src/ReactDebugHooks.js:462–482  ·  view source on GitHub ↗
(
  subscribe: (() => void) => () => void,
  getSnapshot: () => T,
  getServerSnapshot?: () => T,
)

Source from the content-addressed store, hash-verified

460}
461
462function useSyncExternalStore<T>(
463 subscribe: (() => void) => () => void,
464 getSnapshot: () => T,
465 getServerSnapshot?: () => T,
466): T {
467 // useSyncExternalStore() composes multiple hooks internally.
468 // Advance the current hook index the same number of times
469 // so that subsequent hooks have the right memoized state.
470 nextHook(); // SyncExternalStore
471 nextHook(); // Effect
472 const value = getSnapshot();
473 hookLog.push({
474 displayName: null,
475 primitive: 'SyncExternalStore',
476 stackError: new Error(),
477 value,
478 debugInfo: null,
479 dispatcherHookName: 'SyncExternalStore',
480 });
481 return value;
482}
483
484function useTransition(): [
485 boolean,

Callers 12

useLocalStorageFunction · 0.90
useEditorURLFunction · 0.90
useOpenResourceFunction · 0.90
FooFunction · 0.50
CheckIfHydratingFunction · 0.50
AppFunction · 0.50
ChildFunction · 0.50
ThrowWhenHydratingFunction · 0.50
AppFunction · 0.50
CheckIfHydratingFunction · 0.50

Calls 3

getSnapshotFunction · 0.85
nextHookFunction · 0.85
pushMethod · 0.65

Tested by 7

FooFunction · 0.40
CheckIfHydratingFunction · 0.40
AppFunction · 0.40
ChildFunction · 0.40
ThrowWhenHydratingFunction · 0.40
AppFunction · 0.40
CheckIfHydratingFunction · 0.40