Skip to content

Commit

Permalink
fix(eslint-plugin-react-hooks): accepting as expression as a callba…
Browse files Browse the repository at this point in the history
…ck (#28202)

## Summary

Closes #20750

## How did you test this change?

Added a test case
  • Loading branch information
StyleShit authored Feb 1, 2024
1 parent 3d1da1f commit 2efa383
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7765,6 +7765,15 @@ const testsTypescript = {
}
`,
},
{
code: normalizeIndent`
function App(props) {
React.useEffect((() => {
console.log(props.test);
}) as any, [props.test]);
}
`,
},
],
invalid: [
{
Expand Down
9 changes: 9 additions & 0 deletions packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,15 @@ export default {
isEffect,
);
return; // Handled
case 'TSAsExpression':
visitFunctionWithDependencies(
callback.expression,
declaredDependenciesNode,
reactiveHook,
reactiveHookName,
isEffect,
);
return; // Handled
case 'Identifier':
if (!declaredDependenciesNode) {
// No deps, no problems.
Expand Down

0 comments on commit 2efa383

Please sign in to comment.