facebook/react · error · Error

${getComponentNameFromFiber(fiber) || 'Unknown'}.getChildCon

Error message

${getComponentNameFromFiber(fiber) || 'Unknown'}.getChildContext(): key "${contextKey}" is not defined in childContextTypes.

What it means

Legacy context provider path: when a class component declares static childContextTypes and implements getChildContext(), React validates every key of the returned object against childContextTypes before merging it into the parent context. A key present in the returned child context but missing from childContextTypes throws immediately, because consumers could never read an undeclared key.

Source

Thrown at packages/react-reconciler/src/ReactFiberLegacyContext.js:201

        if (!warnedAboutMissingGetChildContext[componentName]) {
          warnedAboutMissingGetChildContext[componentName] = true;
          console.error(
            '%s.childContextTypes is specified but there is no getChildContext() method ' +
              'on the instance. You can either define getChildContext() on %s or remove ' +
              'childContextTypes from it.',
            componentName,
            componentName,
          );
        }
      }
      return parentContext;
    }

    const childContext = instance.getChildContext();
    for (const contextKey in childContext) {
      if (!(contextKey in childContextTypes)) {
        throw new Error(
          `${
            getComponentNameFromFiber(fiber) || 'Unknown'
          }.getChildContext(): key "${contextKey}" is not defined in childContextTypes.`,
        );
      }
    }

    return {...parentContext, ...childContext};
  }
}

function pushContextProvider(workInProgress: Fiber): boolean {
  if (disableLegacyContext) {
    return false;
  } else {
    const instance = workInProgress.stateNode;
    // We push the context as early as possible to ensure stack integrity.
    // If the instance does not exist yet, we will push null at first,

View on GitHub (pinned to eafeac097b)

Solutions

  1. Add the missing key to static childContextTypes with the correct PropTypes type (e.g. theme: PropTypes.string)
  2. Or remove the extra key from the getChildContext() return value if it is unused
  3. Long term, migrate providers and consumers to React.createContext — the legacy API is deprecated and removed in React 17+
  4. Keep getChildContext and childContextTypes keys in one adjacent block so they stay in sync

Example fix

// before
class Provider extends React.Component {
  static childContextTypes = {theme: PropTypes.string};
  getChildContext() {
    return {theme: 'dark', user: this.props.user}; // 'user' not declared -> throws
  }
}

// after
class Provider extends React.Component {
  static childContextTypes = {
    theme: PropTypes.string,
    user: PropTypes.object, // declared
  };
  getChildContext() {
    return {theme: 'dark', user: this.props.user};
  }
}
Defensive patterns

Strategy: validation

Validate before calling

// Dev-time guard: validate getChildContext keys against childContextTypes before rendering
development &&
  Object.keys(new Provider().getChildContext() ?? {}).forEach((key) => {
    if (!(key in Provider.childContextTypes)) {
      throw new Error(`childContextTypes missing key: ${key}`);
    }
  });

Prevention

When it happens

Trigger: A class component whose getChildContext() returns an object containing a key not declared in its static childContextTypes map (typo, casing difference, or a newly added key), rendered while legacy context is enabled (React 16.x line — the API is removed in newer majors).

Common situations: Maintaining pre-createContext class codebases; third-party libraries still on the legacy context API; copy-paste additions to getChildContext without updating childContextTypes; PropTypes typos between the two definitions.

Related errors


AI-assisted analysis of facebook/react@eafeac097b (2026-08-21). Data as JSON: /api/errors/4bebf29e79699117. Report an issue: GitHub.