Skip to content

linter: react-hooks/exhaustive-deps reports state setters when React is aliased #23150

Description

@jeanne-cai

What version of Oxlint are you using?

1.68.0

What command did you run?

yarn oxlint -c oxlint.config.mjs

What does your .oxlintrc.json (or oxlint.config.ts) config file look like?

import { defineConfig } from 'oxlint';

export default defineConfig({
    categories: {
        correctness: 'off',
    },
    plugins: ['react-hooks'],
    rules: {
        'react-hooks/exhaustive-deps': 'error',
    },
});

What happened?

The rule reports state setters as missing dependencies when React is imported under a name other than React (e.g., in tests).

test.tsx:

const ReactActual = jest.requireActual('react');
const Component = ({ filter }) => {
    const [data, setData] = ReactActual.useState(filter);
    ReactActual.useEffect(() => {
        setData(filter);
    }, [filter]);

    return <div>test</div>;
};

Output:

  × react-hooks(exhaustive-deps): React Hook useEffect has a missing dependency: 'setData'
   ╭─[test.tsx:6:8]
 4 │     ReactActual.useEffect(() => {
 5 │         setData(filter);
   ·         ───┬───
   ·            ╰── useEffect uses `setData` here
 6 │     }, [filter]);
   ·        ────────
 7 │ };
   ╰────
  help: Either include it or remove the dependency array.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions