Skip to content

Commit 2efa383

Browse files
authored
fix(eslint-plugin-react-hooks): accepting as expression as a callback (#28202)
## Summary Closes #20750 ## How did you test this change? Added a test case
1 parent 3d1da1f commit 2efa383

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js

+9
Original file line numberDiff line numberDiff line change
@@ -7765,6 +7765,15 @@ const testsTypescript = {
77657765
}
77667766
`,
77677767
},
7768+
{
7769+
code: normalizeIndent`
7770+
function App(props) {
7771+
React.useEffect((() => {
7772+
console.log(props.test);
7773+
}) as any, [props.test]);
7774+
}
7775+
`,
7776+
},
77687777
],
77697778
invalid: [
77707779
{

packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js

+9
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,15 @@ export default {
12231223
isEffect,
12241224
);
12251225
return; // Handled
1226+
case 'TSAsExpression':
1227+
visitFunctionWithDependencies(
1228+
callback.expression,
1229+
declaredDependenciesNode,
1230+
reactiveHook,
1231+
reactiveHookName,
1232+
isEffect,
1233+
);
1234+
return; // Handled
12261235
case 'Identifier':
12271236
if (!declaredDependenciesNode) {
12281237
// No deps, no problems.

0 commit comments

Comments
 (0)