react-doctor/prefer-use
Replace useContext(Context) with the React 19 use(Context) API, which reads the same value but may be called conditionally
- Category: State & Effects
- Severity: warn
- Source:
oxlint-plugin-react-doctor - Framework: global
- Enabled when: always
- Documentation: https://react.dev/reference/react/use
Validation prompt
Use this to decide whether a fired diagnostic is real or a false positive.
Fires on a useContext(SomeContext) call (analogous to eslint-react no-use-context), recommending the React 19 use(SomeContext) API, which reads the same context value but may be called inside conditionals and loops rather than only at the component top level. Only meaningful on React 19+ projects; use() is unavailable before 19. False positive: a useContext re-exported through a custom wrapper hook, where the migration belongs at the wrapper definition rather than each call site.
Fix prompt
Use this once validation confirms the diagnostic is real.
Swap useContext for use at the call site: const theme = use(ThemeContext) replaces const theme = useContext(ThemeContext). Remove the useContext import only if no other useContext usage remains in the file. Unlike useContext, use may be called conditionally, so the read can move inside the branch that needs it. See https://react.dev/reference/react/use
Related rules
More State & Effects rules from the rules reference:
react-doctor/prefer-use-effect-event: Wrap the callback with `useEffectEvent(callback)` (React 19+) and call the resulting binding from inside the sub-handler. The Effect Event captures the latest props/state without being a reactive dep, so the effect doesn't re-subscribe on every parent render. See https://react.dev/reference/react/useEffectEventreact-doctor/prefer-use-sync-external-store: Replace the `useState(getSnapshot())` + `useEffect(() => store.subscribe(() => setSnapshot(getSnapshot())))` pair with `useSyncExternalStore(store.subscribe, getSnapshot)`. The hook handles tearing during concurrent renders and SSR snapshots; the manual subscribe pattern doesn'treact-doctor/prefer-useReducer: Group related state: `const [state, dispatch] = useReducer(reducer, { field1, field2, ... })`react-doctor/rerender-dependencies: Extract to a useMemo, useRef, or module-level constant so the reference is stableeffect/no-adjust-state-on-prop-change: Disallow adjusting state in an effect when a prop changes.