react-doctor/no-legacy-context-api
Replace `childContextTypes` + `getChildContext` with `const MyContext = createContext(...)` + `<MyContext.Provider value={...}>`; replace `contextTypes` with `static contextType = MyContext` (single context) or `useContext()` / `use()` from a function component. The provider and every consumer must migrate together — partial migrations leave consumers reading the wrong context.
- Category: Correctness
- Severity: error
- Source:
oxlint-plugin-react-doctor - Framework: global
- Enabled when: always
Validation prompt
Use this to decide whether a fired diagnostic is real or a false positive.
Fires on class members or top-level UppercaseIdentifier.childContextTypes / contextTypes / getChildContext = {...} assignments — the legacy context API removed in React 19. Both the provider (childContextTypes + getChildContext) and consumer (contextTypes) shapes are flagged. Migration is cross-file, so confirm you are not viewing a partial migration where the modern createContext already coexists with the legacy form.
Fix prompt
Use this once validation confirms the diagnostic is real.
Replace childContextTypes + getChildContext with a module-level const MyContext = createContext(defaultValue) and wrap children in <MyContext.Provider value={...}>. Replace consumer contextTypes with static contextType = MyContext (single context) or useContext(MyContext) / use(MyContext) inside function components. Migrate the provider and every consumer in the same commit to avoid silent context mismatches. See https://react.dev/reference/react/createContext
Related rules
More Correctness rules from the rules reference:
react-doctor/no-namespace: Drop the namespace and use a plain (Pascal-cased) component or DOM tag.react-doctor/no-nested-component-definition: Move to a separate file or to module scope above the parent componentreact-doctor/no-prevent-default: Use `<form action={serverAction}>` (works without JS) or `<button>` instead of `<a>` with preventDefaultreact-doctor/no-random-key: Replace the fresh-each-render key with a stable id from the item: key={item.id}react-doctor/no-this-in-sfc: Use the function's `props` parameter instead of `this.props` in stateless function components.