diff --git a/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js b/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js index c8204283986e8..9322952fa4f37 100644 --- a/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js +++ b/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js @@ -369,6 +369,20 @@ const tests = { } `, }, + { + code: normalizeIndent` + function MyComponent({myEffect}) { + useEffect(myEffect, [,myEffect]); + } + `, + }, + { + code: normalizeIndent` + function MyComponent({myEffect}) { + useEffect(myEffect, [,myEffect,,]); + } + `, + }, { code: normalizeIndent` let local = {}; diff --git a/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js b/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js index 6fc155d45598a..33ff43a66355c 100644 --- a/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js +++ b/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js @@ -145,7 +145,7 @@ export default { if ( declaredDependenciesNode.elements && declaredDependenciesNode.elements.some( - el => el.type === 'Identifier' && el.name === callback.name, + el => el && el.type === 'Identifier' && el.name === callback.name, ) ) { // If it's already in the list of deps, we don't care because