react/jsx-no-leaked-render
eslint-plugin-react
Safe autofix
eslint.config.js
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/jsx-no-leaked-render": "error",
},
},
];const Component = ({ count, title }) => {
return <div>{count && title}</div>
}const Component = ({ count }) => {
return <div>{count && <span>There are {count} results</span>}</div>
}const Component = ({ elements }) => {
return <div>{elements.length && <List elements={elements} />}</div>
}const Component = ({ elements }) => {
return <div>{elements}</div>
}// An OR condition it's considered valid since it's assumed as a way
// to render some fallback if the first value is falsy, not to render something conditionally.
const Component = ({ customTitle }) => {
return <div>{customTitle || defaultTitle}</div>
}const Component = ({ elements }) => {
return <div>There are {elements.length} elements</div>
}Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
react/jsx-no-leaked-render
eslint-plugin-react
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/jsx-no-leaked-render": "error",
},
},
];Oxlint does not have this rule.
suspicious/noLeakedRender
suspicious · since 2.3.8
{
"linter": {
"rules": {
"suspicious": {
"noLeakedRender": "error"
}
}
}
}React components should not render non-boolean condition values
Ensure destructuring and symmetric naming of useState hook value and setter variables