From e002fc73f070dc4cdd90c20a2064d2b6bd40a4cb Mon Sep 17 00:00:00 2001 From: eps1lon Date: Sat, 1 Oct 2022 18:02:43 +0200 Subject: [PATCH] fix: Don't consider Hooks as Components --- .../__tests__/ESLintRuleNoNestedComponents-test.js | 11 +++++++++++ .../src/NoNestedComponents.js | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleNoNestedComponents-test.js b/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleNoNestedComponents-test.js index 380026f0ca8dc..b47635f9b2a98 100644 --- a/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleNoNestedComponents-test.js +++ b/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleNoNestedComponents-test.js @@ -846,6 +846,17 @@ const tests = { })) `, }, + { + code: normalizeIndent` + function useCustomHook() { + const useNestedHook = () => { + React.useRef(); + } + useNestedHook(); + useNestedHook(); + } + `, + }, ], invalid: [ { diff --git a/packages/eslint-plugin-react-hooks/src/NoNestedComponents.js b/packages/eslint-plugin-react-hooks/src/NoNestedComponents.js index e8b964fe5ab26..fce2e5de806dc 100644 --- a/packages/eslint-plugin-react-hooks/src/NoNestedComponents.js +++ b/packages/eslint-plugin-react-hooks/src/NoNestedComponents.js @@ -102,7 +102,7 @@ function isInsideComponentOrHook(node) { function isComponent(node) { const functionName = getFunctionName(node); if (functionName) { - if (isComponentName(functionName) || isHook(functionName)) { + if (isComponentName(functionName)) { return true; } }