GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Bug: react-hooks/exhaustive-deps does not accept readonly arrays as deps · Issue #25844 · react/react

Bug: react-hooks/exhaustive-deps does not accept readonly arrays as deps #25844

New issue
Copy link
New issue
Copy link
Closed
#28189
Closed
Bug: react-hooks/exhaustive-deps does not accept readonly arrays as deps#25844
#28189
Copy link
Labels
Component: ESLint RulesStatus: UnconfirmedA potential issue that we haven't yet confirmed as a bug

Description

@milichev
milichev
opened on Dec 7, 2022
Issue body actions

React version:

react: 16.8.6
eslint-plugin-react-hooks: 4.2.0

Steps To Reproduce

  1. Properly configure the react-hooks/exhaustive-deps ESLint rule
  2. In your code, pass the deps argument as read-only array literal:
const useExample = ({ value, callback }: { value: number; callback: (value: number) => void }) => {
    useEffect(
        () => {
            callback(value);
        },
        // In the next line, the const assertion makes the react-hooks/exhaustive-deps rule to emit an error
        [value, callback] as const
    );
};

The current behavior

ESLint emits an error: React Hook useEffect was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies. (react-hooks/exhaustive-deps)

At the same time, useEffect hook itself accepts read-only arrays:

// node_modules/@types/react/index.d.ts
type DependencyList = ReadonlyArray<any>;
function useEffect(effect: EffectCallback, deps?: DependencyList): void;

The tsc with rather strict compilation options success too.

The expected behavior

The react-hooks/exhaustive-deps rule should accept readonly array literals as well.

Rationale

A strongly typed deps parameter is used in a custom hook for type inference.

image

I'm going to take a look myself once I have a slack time (it should not be complex: something like checking the isReadonly flag of the array expression node), but would appreciate any input or contribution.

Activity

  1. milichev
    added
    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug
    on Dec 7, 2022
  2. eps1lon
    added
    Component: ESLint Rules
    on Dec 7, 2022
  3. StyleShit
    added a commit that references this issue on Feb 1, 2024

    fix(eslint-plugin-react-hooks): accepting `as` expressions as deps array

    This issue will close once commit 6129f47 is merged into the 'main' branch.
    6129f47
  4. eps1lon
    closed this as completedin #28189on Feb 1, 2024
  5. eps1lon
    added a commit that references this issue on Feb 1, 2024

    fix(eslint-plugin-react-hooks): accepting `as` expressions as deps ar…

    This issue will close once commit a1433ca is merged into the 'main' branch.
    a1433ca
  6. github-actions
    added a commit that references this issue on Feb 1, 2024

    fix(eslint-plugin-react-hooks): accepting `as` expressions as deps ar…

    This issue will close once commit 9628430 is merged into the 'main' branch.
    9628430
  7. gaearon
    added a commit that references this issue on Feb 3, 2024

    fix(eslint-plugin-react-hooks): accepting `as` expressions as deps ar…

    This issue will close once commit b3f8de8 is merged into the 'main' branch.
    b3f8de8
  8. EdisonVan
    added a commit that references this issue on Apr 15, 2024

    fix(eslint-plugin-react-hooks): accepting `as` expressions as deps ar…

    This issue will close once commit a1c219d is merged into the 'main' branch.
    a1c219d
  9. bigfootjon
    added a commit that references this issue on Apr 18, 2024

    fix(eslint-plugin-react-hooks): accepting `as` expressions as deps ar…

    This issue will close once commit 86906e8 is merged into the 'main' branch.
    86906e8
  10. hanzo-dev
    added a commit that references this issue on Sep 9, 2026

    fix(eslint-plugin-react-hooks): accepting `as` expressions as deps ar…

    This issue will close once commit 3255d58 is merged into the 'main' branch.
    3255d58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: ESLint RulesStatus: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.