Skip to content

Commit 0c17fe8

Browse files
ljharbartemxknpv
andcommitted
fixup: Update docs/rules/jsx-no-leaked-render.md
Co-authored-by: Artyom Konoplyov <[email protected]>
1 parent b972e3a commit 0c17fe8

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Diff for: docs/rules/jsx-no-leaked-render.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,32 @@ const Component = ({ elements }) => {
152152
The supported options are:
153153

154154
### `ignoreAttributes`
155+
Boolean. When set to `true`, this option ignores all attributes except for `children` during validation, preventing false positives in scenarios where these attributes are used safely or validated internally. Default is `false`.
155156

156-
*TODO*
157+
It can be set like:
158+
```json5
159+
{
160+
// ...
161+
"react/jsx-no-leaked-render": [<enabled>, { "ignoreAttributes": true }]
162+
// ...
163+
}
164+
```
165+
166+
Example of incorrect usage with default setting (`ignoreAttributes: false`) and the rule enabled (consider `value` might be undefined):
167+
168+
```jsx
169+
function MyComponent({ value }) {
170+
return (
171+
<MyChildComponent nonChildrenProp={value && 'default'}>
172+
{value && <MyInnerChildComponent />}
173+
</MyChildComponent>
174+
);
175+
}
176+
```
177+
178+
This would trigger a warning in both `nonChildrenProp` and `children` props because `value` might be undefined.
157179

180+
By setting `ignoreAttributes` to `true`, the rule will not flag this scenario in `nonChildrenProp`, reducing false positives, **but will keep the warning of `children` being leaked**.
158181
### `validStrategies`
159182

160183
An array containing `"coerce"`, `"ternary"`, or both (default: `["ternary", "coerce"]`) - Decide which strategies are considered valid to prevent leaked renders (at least 1 is required). The "coerce" option will transform the conditional of the JSX expression to a boolean. The "ternary" option transforms the binary expression into a ternary expression returning `null` for falsy values. The first option from the array will be the strategy used when autofixing, so the order of the values matters.

0 commit comments

Comments
 (0)