eslint-plugin-react
eslint-plugin-react copied to clipboard
False positives for `no-this-in-sfc` for functions returning null
In the following cases the functions should not be considered a component, if they returns only null without jsx.
https://github.com/jsx-eslint/eslint-plugin-react/blob/4b4bba91ddebe27cf6bdd9f86d2b9a824a07a8fb/tests/lib/rules/no-this-in-sfc.js#L245-L255
https://github.com/jsx-eslint/eslint-plugin-react/blob/4b4bba91ddebe27cf6bdd9f86d2b9a824a07a8fb/tests/lib/rules/no-this-in-sfc.js#L278-L290
https://github.com/jsx-eslint/eslint-plugin-react/blob/4b4bba91ddebe27cf6bdd9f86d2b9a824a07a8fb/tests/lib/rules/no-this-in-sfc.js#L291-L302
Yes, they should - components don't have to return jsx, they can return null, numbers, strings, or arrays of such (and in react 18+, undefined).
I got you. But do you think these test cases should be reported? If these nulls are replaced with numbers, strings, or arrays, should they be reported?
There is a distinction between what React engine considered a component, and what a developer considered a component. For a function returning only null or numbers, more likely than not, developers do not considered it a component.
More likely than not, but it’s sometimes better to have false positives than to miss a component.
Components that only return null are far more common than any other kind of non-jsx-returning component, I’m pretty sure, so i think it’s fine to catch the former and not the latter.
I think this is resolved, but please file a new issue if not.