Skip to content

Commit 090c6ed

Browse files
authored
[eslint-plugin-react-hooks]: handling sparse array when no-inline callback (facebook#19145)
1 parent cc7c1ae commit 090c6ed

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,20 @@ const tests = {
369369
}
370370
`,
371371
},
372+
{
373+
code: normalizeIndent`
374+
function MyComponent({myEffect}) {
375+
useEffect(myEffect, [,myEffect]);
376+
}
377+
`,
378+
},
379+
{
380+
code: normalizeIndent`
381+
function MyComponent({myEffect}) {
382+
useEffect(myEffect, [,myEffect,,]);
383+
}
384+
`,
385+
},
372386
{
373387
code: normalizeIndent`
374388
let local = {};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export default {
145145
if (
146146
declaredDependenciesNode.elements &&
147147
declaredDependenciesNode.elements.some(
148-
el => el.type === 'Identifier' && el.name === callback.name,
148+
el => el && el.type === 'Identifier' && el.name === callback.name,
149149
)
150150
) {
151151
// If it's already in the list of deps, we don't care because

0 commit comments

Comments
 (0)