diff --git a/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js b/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js index 3d60a36824d..30fac44462a 100644 --- a/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js +++ b/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js @@ -45,6 +45,14 @@ const allTests = { } `, }, + { + code: normalizeIndent` + // Valid because components with underscore prefix followed by uppercase are components. + function _PrivateComponent() { + useHook(); + } + `, + }, { syntax: 'flow', code: normalizeIndent` diff --git a/packages/eslint-plugin-react-hooks/src/rules/RulesOfHooks.ts b/packages/eslint-plugin-react-hooks/src/rules/RulesOfHooks.ts index ca82c99e2f5..3353214080b 100644 --- a/packages/eslint-plugin-react-hooks/src/rules/RulesOfHooks.ts +++ b/packages/eslint-plugin-react-hooks/src/rules/RulesOfHooks.ts @@ -55,7 +55,7 @@ function isHook(node: Node): boolean { * always start with an uppercase letter. */ function isComponentName(node: Node): boolean { - return node.type === 'Identifier' && /^[A-Z]/.test(node.name); + return node.type === 'Identifier' && /^_?[A-Z]/.test(node.name); } function isReactFunction(node: Node, functionName: string): boolean {