react-doctor/no-unsafe
Replace UNSAFE_componentWillMount / WillReceiveProps / WillUpdate with their modern lifecycle equivalents.
- Category: Correctness
- Severity: warn
- Source:
oxlint-plugin-react-doctor - Framework: global
- Enabled when: always
- Documentation: https://oxc.rs/docs/guide/usage/linter/rules/react/no-unsafe
Validation prompt
Use this to decide whether a fired diagnostic is real or a false positive.
Fires when a React class component (detected via getParentComponent) or a createReactClass ES5 component defines a method/property named UNSAFE_componentWillMount, UNSAFE_componentWillReceiveProps, or UNSAFE_componentWillUpdate; the non-prefixed aliases (componentWillMount etc.) are only flagged when settings.react-doctor.noUnsafe.checkAliases is true. The prefixed methods are additionally skipped when settings.react.version is below 16.3 (an unknown version is treated as modern and still flagged). False positive boundary: an identically named method on a class that is NOT a React component (e.g. extends Bar, a plain helper class) is correctly NOT flagged — confirm the enclosing class actually extends React.Component / PureComponent or is a createReactClass call before acting.
Fix prompt
Use this once validation confirms the diagnostic is real.
Migrate each unsafe lifecycle to its async-safe replacement: move side effects from componentWillMount to componentDidMount, derive prop-driven state in static getDerivedStateFromProps(props, state) instead of componentWillReceiveProps, and capture pre-update info in getSnapshotBeforeUpdate / handle it in componentDidUpdate instead of componentWillUpdate. For most components, prefer porting the class to a function component with hooks (useEffect, useState). See https://oxc.rs/docs/guide/usage/linter/rules/react/no-unsafe
Related rules
More Correctness rules from the rules reference:
react-doctor/react-in-jsx-scope: If on React 17+ with the new JSX transform, disable this rule; otherwise import React at the top of the file.react-doctor/rendering-conditional-render: Change to `{items.length > 0 && <List />}` or use a ternary: `{items.length ? <List /> : null}`react-doctor/rendering-hydration-mismatch-time: Wrap dynamic time/random values in useEffect+useState (client-only) or add suppressHydrationWarning to the parent if intentionalreact-doctor/style-prop-object: Pass the `style` prop as an object literal like `{{ color: 'red' }}`, never a string or other primitive.react-doctor/void-dom-elements-no-children: Remove children from the void element, or use a non-void element if children are needed.