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

Function createContext

packages/react/src/ReactContext.js:14–46  ·  view source on GitHub ↗
(defaultValue: T)

Source from the content-addressed store, hash-verified

12import type {ReactContext} from 'shared/ReactTypes';
13
14export function createContext<T>(defaultValue: T): ReactContext<T> {
15 // TODO: Second argument used to be an optional `calculateChangedBits`
16 // function. Warn to reserve for future use?
17
18 const context: ReactContext<T> = {
19 $$typeof: REACT_CONTEXT_TYPE,
20 // As a workaround to support multiple concurrent renderers, we categorize
21 // some renderers as primary and others as secondary. We only expect
22 // there to be two concurrent renderers at most: React Native (primary) and
23 // Fabric (secondary); React DOM (primary) and React ART (secondary).
24 // Secondary renderers store their context values on separate fields.
25 _currentValue: defaultValue,
26 _currentValue2: defaultValue,
27 // Used to track how many concurrent renderers this context currently
28 // supports within in a single renderer. Such as parallel server rendering.
29 _threadCount: 0,
30 // These are circular
31 Provider: (null: any),
32 Consumer: (null: any),
33 };
34
35 context.Provider = context;
36 context.Consumer = {
37 $$typeof: REACT_CONSUMER_TYPE,
38 _context: context,
39 };
40 if (__DEV__) {
41 context._currentRenderer = null;
42 context._currentRenderer2 = null;
43 }
44
45 return context;
46}

Callers 15

index.jsFile · 0.90
index.jsFile · 0.90
Contexts.jsFile · 0.90
CustomHooks.jsFile · 0.90
TimelineContext.jsFile · 0.90
useTheme.jsFile · 0.90
cache.jsFile · 0.90
ModalDialog.jsFile · 0.90
context.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected