[eslint-plugin-react-hooks]: handling sparse array when no-inline callback (#19145)
YeonJuan committed
Jun 18, 2020 at 01:29 UTC
090c6ed7515b63c9aa7c42659973bfc179691006
2 files changed
+15
-1
packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js
+14
@@ -369,6 +369,20 @@ const tests = {
369
}
370
`,
371
},
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
+ },
386
{
387
code: normalizeIndent`
388
let local = {};
packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
+1
-1
@@ -145,7 +145,7 @@ export default {
145
if (
146
declaredDependenciesNode.elements &&
147
declaredDependenciesNode.elements.some(
148
- el => el.type === 'Identifier' && el.name === callback.name,
148
+ el => el && el.type === 'Identifier' && el.name === callback.name,
149
)
150
) {
151
// If it's already in the list of deps, we don't care because