Skip to content

Commit

Permalink
[Fix] display-name: fix false positive when using memo
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot committed Jun 1, 2022
1 parent e7fc22f commit 06a82b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/util/Components.js
Expand Up @@ -515,7 +515,7 @@ function componentRule(rule, context) {

// Case like `React.memo(() => <></>)` or `React.forwardRef(...)`
const pragmaComponentWrapper = utils.getPragmaComponentWrapper(node);
if (pragmaComponentWrapper) {
if (pragmaComponentWrapper && utils.isReturningJSXOrNull(node)) {
return pragmaComponentWrapper;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/lib/rules/display-name.js
Expand Up @@ -588,6 +588,19 @@ ruleTester.run('display-name', rule, {
}
`,
},
{
// issue #3303
code: `
function MyComponent(props) {
return <b>{props.name}</b>;
}
const MemoizedMyComponent = React.memo(
MyComponent,
(prevProps, nextProps) => prevProps.name === nextProps.name
)
`,
},
]),

invalid: parsers.all([
Expand Down

0 comments on commit 06a82b5

Please sign in to comment.