Skip to content

Commit b9aa04b

Browse files
golopotljharb
authored andcommitted
[Fix] display-name: fix false positive when using memo
1 parent e7fc22f commit b9aa04b

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
88
### Fixed
99
* [`display-name`]: fix false positive for HOF returning only nulls ([#3291][] @golopot)
1010
* [`jsx-no-leaked-render`]: avoid unnecessary negation operators and ternary branches deletion ([#3299][] @Belco90)
11+
* [`display-name`]: fix false positive when using memo ([#3304][] @golopot)
1112

1213
### Changed
1314
* [Docs] [`jsx-tag-spacing`]: rename option from [#3264][] ([#3294[] @ljharb)
1415
* [Docs] [`jsx-key`]: split the examples ([#3293][] @ioggstream)
1516

17+
[#3304]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3304
1618
[#3299]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3299
1719
[#3294]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3294
1820
[#3293]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3293

lib/util/Components.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ function componentRule(rule, context) {
515515

516516
// Case like `React.memo(() => <></>)` or `React.forwardRef(...)`
517517
const pragmaComponentWrapper = utils.getPragmaComponentWrapper(node);
518-
if (pragmaComponentWrapper) {
518+
if (pragmaComponentWrapper && utils.isReturningJSXOrNull(node)) {
519519
return pragmaComponentWrapper;
520520
}
521521

tests/lib/rules/display-name.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,19 @@ ruleTester.run('display-name', rule, {
588588
}
589589
`,
590590
},
591+
{
592+
// issue #3303
593+
code: `
594+
function MyComponent(props) {
595+
return <b>{props.name}</b>;
596+
}
597+
598+
const MemoizedMyComponent = React.memo(
599+
MyComponent,
600+
(prevProps, nextProps) => prevProps.name === nextProps.name
601+
)
602+
`,
603+
},
591604
]),
592605

593606
invalid: parsers.all([

0 commit comments

Comments
 (0)