Skip to content

Commit

Permalink
fix(eslint-plugin-react-hooks): accepting as expression as a callback
Browse files Browse the repository at this point in the history
Closes #20750
  • Loading branch information
StyleShit committed Feb 1, 2024
1 parent a1433ca commit e0b608c
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 e0b608c

Please sign in to comment.