-
Notifications
You must be signed in to change notification settings - Fork 47k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: react-hooks/exhaustive-deps does not accept readonly arrays as deps #25844
Labels
Component: ESLint Rules
Status: Unconfirmed
A potential issue that we haven't yet confirmed as a bug
Comments
milichev
added
the
Status: Unconfirmed
A potential issue that we haven't yet confirmed as a bug
label
Dec 7, 2022
StyleShit
added a commit
to StyleShit/react
that referenced
this issue
Feb 1, 2024
github-actions bot
pushed a commit
that referenced
this issue
Feb 1, 2024
…ray (#28189) ## Summary This PR closes #25844 The original issue talks about `as const`, but seems like it fails for any `as X` expressions since it adds another nesting level to the AST. EDIT: Also closes #20162 ## How did you test this change? Added unit tests DiffTrain build for [a1433ca](a1433ca)
EdisonVan
pushed a commit
to EdisonVan/react
that referenced
this issue
Apr 15, 2024
…ray (facebook#28189) ## Summary This PR closes facebook#25844 The original issue talks about `as const`, but seems like it fails for any `as X` expressions since it adds another nesting level to the AST. EDIT: Also closes facebook#20162 ## How did you test this change? Added unit tests
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Component: ESLint Rules
Status: Unconfirmed
A potential issue that we haven't yet confirmed as a bug
React version:
Steps To Reproduce
react-hooks/exhaustive-deps
ESLint ruledeps
argument as read-only array literal: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:The
tsc
with rather strict compilation options success too.The expected behavior
The
react-hooks/exhaustive-deps
rule should acceptreadonly
array literals as well.Rationale
A strongly typed
deps
parameter is used in a custom hook for type inference.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.The text was updated successfully, but these errors were encountered: