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

Function processChildContext

packages/react-server/src/ReactFizzLegacyContext.js:42–83  ·  view source on GitHub ↗
(
  instance: any,
  type: any,
  parentContext: Object,
  childContextTypes: Object,
)

Source from the content-addressed store, hash-verified

40}
41
42export function processChildContext(
43 instance: any,
44 type: any,
45 parentContext: Object,
46 childContextTypes: Object,
47): Object {
48 if (disableLegacyContext) {
49 return parentContext;
50 } else {
51 // TODO (bvaughn) Replace this behavior with an invariant() in the future.
52 // It has only been added in Fiber to match the (unintentional) behavior in Stack.
53 if (typeof instance.getChildContext !== 'function') {
54 if (__DEV__) {
55 const componentName = getComponentNameFromType(type) || 'Unknown';
56
57 if (!warnedAboutMissingGetChildContext[componentName]) {
58 warnedAboutMissingGetChildContext[componentName] = true;
59 console.error(
60 '%s.childContextTypes is specified but there is no getChildContext() method ' +
61 'on the instance. You can either define getChildContext() on %s or remove ' +
62 'childContextTypes from it.',
63 componentName,
64 componentName,
65 );
66 }
67 }
68 return parentContext;
69 }
70
71 const childContext = instance.getChildContext();
72 for (const contextKey in childContext) {
73 if (!(contextKey in childContextTypes)) {
74 throw new Error(
75 `${
76 getComponentNameFromType(type) || 'Unknown'
77 }.getChildContext(): key "${contextKey}" is not defined in childContextTypes.`,
78 );
79 }
80 }
81 return {...parentContext, ...childContext};
82 }
83}

Callers 1

finishClassComponentFunction · 0.90

Calls 3

getComponentNameFromTypeFunction · 0.85
errorMethod · 0.65
getChildContextMethod · 0.45

Tested by

no test coverage detected