Skip to content

[eslint-plugin-react-hooks] allow for underscore prefixed component names #33131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ const allTests = {
});
`,
},
{
code: normalizeIndent`
// Valid because hooks can be used in named function arguments to
// memo.
const MemoizedFunction = memo(function _MyComponent(props) {
useHook();
return <button {...props} />
});
`,
},
{
code: normalizeIndent`
// Valid because classes can call functions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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 {
Expand Down