diff --git a/CHANGELOG.md b/CHANGELOG.md index 54cb112a4d..c5c9253d18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange * [`no-unknown-property`]: add `viewBox` on `marker` ([#3416][] @ljharb) * [`no-unknown-property`]: add `noModule` on `script` ([#3414][] @ljharb) * [`no-unknown-property`]: allow `onLoad` on `` ([#3415][] @OleksiiKachan) +* [`no-multi-comp`]: do not detect a function property returning only null as a component ([#3412][] @ljharb) ### Changed @@ -18,6 +19,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange [#3415]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3415 [#3414]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3414 [#3413]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3413 +[#3412]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3412 ## [7.31.7] - 2022.09.05 diff --git a/lib/util/Components.js b/lib/util/Components.js index aa511ebdf3..7b931c2234 100644 --- a/lib/util/Components.js +++ b/lib/util/Components.js @@ -592,6 +592,10 @@ function componentRule(rule, context) { return undefined; } + if (parent.type === 'Property' && utils.isReturningOnlyNull(node)) { + return undefined; + } + return node; } diff --git a/tests/lib/rules/no-multi-comp.js b/tests/lib/rules/no-multi-comp.js index d7c71fc3e2..37402facbe 100644 --- a/tests/lib/rules/no-multi-comp.js +++ b/tests/lib/rules/no-multi-comp.js @@ -236,6 +236,35 @@ ruleTester.run('no-multi-comp', rule, { export default MenuList; `, }, + { + code: ` + const MenuList = forwardRef(({ onClose, ...props }, ref) => { + const onLogout = useCallback(() => { + onClose() + }, [onClose]) + + return ( + + + Logout + + + ) + }) + + MenuList.displayName = 'MenuList' + + MenuList.propTypes = { + onClose: PropTypes.func + } + + MenuList.defaultProps = { + onClose: () => null + } + + export default MenuList + `, + }, ]), invalid: parsers.all([