Rules
no-leaked-conditional-rendering
Full Name in eslint-plugin-react-x
Full Name in @eslint-react/eslint-plugin
Features
🔍
💭
Presets
recommended-type-checked
What it does
Prevents problematic leaked values from being rendered.
Using the &&
operator to render some element conditionally in JSX can cause unexpected values being rendered, or even crashing the rendering.
Examples
In React, you might end up rendering unexpected values like 0
or NaN
. In React Native, your render method will even crash if you render these values:
This can be avoided by:
- coercing the conditional to a boolean:
{!!someValue && <Something />}
- transforming the binary expression into a ternary expression which returns null for falsy values:
{someValue ? <Something /> : null}
Failing
Passing
Implementation
Further Reading
See Also
no-complex-conditional-rendering
Warns when conditional rendering is too complex.