jsx-no-leaked-render
should only complain if there is a certian leaked renderΒ #3754
Description
Is there an existing issue for this?
- I have searched the existing issues and my issue is unique
Description Overview
This was previously discussed in #3719
The goal of the rule is to avoid leaked render specially when the left side of &&
is 0
, NaN
, or ""
because react-dom will render a 0
in the first case (while some would expect to render nothing) and react-native will crach in the three. Currently, the rule complain for potential leaked render while most of the cases there is no any leaked render. for example, when the left side is boolean, undefined
, null
, ojbect, or array.
The following code is an eslint error, while it doesn't have any side effects.
let data: Item[] | undefined = getData();
return (
<div>
{data && <List items={data} />}
</div>
)
Proposal
It should only complain if the left side is one of the potential leaked render number
(0
or NaN
) or string (""
). Others types should be valid. AFAIK, this is possible with the @typescript-eslint/parser
eslint-plugin-react version
7.33.2
eslint version
8.56.0
node version
22
Activity