Skip to content

linter: react-hooks/exhaustive-deps false positive when dependency uses as const #23151

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?

This rule incorrectly flags stable const value.

test.tsx

const Component = () => {
    const DATA = 'test' as const;
    const data = React.useMemo(() => DATA, []);
    return <div>{data}</div>;
};

Output:

  × react-hooks(exhaustive-deps): React Hook useMemo has a missing dependency: 'DATA'
   ╭─[test.tsx:3:44]
 2 │     const DATA = 'test' as const;
 3 │     const data = React.useMemo(() => DATA, []);
   ·                                      ──┬─  ──
   ·                                        ╰── useMemo uses `DATA` here
 4 │     return <div>{data}</div>;
   ╰────
  help: Either include it or remove the dependency array.

Metadata

Metadata

Assignees

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