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}