Skip to content

Commit 5234789

Browse files
committed
[docs] - Provide more clarity about destructuring props over rest spread.
Fixes #7
1 parent 4455c06 commit 5234789

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

docs/rules/img-has-alt.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,31 @@ To tell this plugin to also check your `Image` element, specify this in your `.e
4141
}
4242
```
4343

44-
Note that passing props as spread attribute without `alt` explicitly defined will cause this rule to fail. Explicitly pass down `alt` prop or use `role="presentation"` for rule to pass. Use `Image` component above as a reference for destructuring and applying the prop. **It is a good thing to explicitly pass props that you expect to be passed for self-documentation.**
44+
Note that passing props as spread attribute without `alt` explicitly defined will cause this rule to fail. Explicitly pass down `alt` prop or use `role="presentation"` for rule to pass. Use `Image` component above as a reference for destructuring and applying the prop. **It is a good thing to explicitly pass props that you expect to be passed for self-documentation.** For example:
45+
#### Bad
46+
```jsx
47+
function Foo(props) {
48+
return <img {...props} />
49+
}
50+
```
51+
52+
#### Good
53+
```jsx
54+
function Foo({ alt, ...props}) {
55+
return <img alt={alt} {...props} />
56+
}
57+
58+
// OR
59+
60+
function Foo(props) {
61+
const {
62+
alt,
63+
...otherProps
64+
} = props;
65+
66+
return <img alt={alt} {...otherProps} />
67+
}
68+
```
4569

4670
### Succeed
4771
```jsx

docs/rules/label-has-for.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,31 @@ To tell this plugin to also check your `Label` element, specify this in your `.e
4242
}
4343
```
4444

45-
Note that passing props as spread attribute without `htmlFor` explicitly defined will cause this rule to fail. Explicitly pass down `htmlFor` prop for rule to pass. The prop must have an actual value to pass. Use `Label` component above as a reference. **It is a good thing to explicitly pass props that you expect to be passed for self-documentation.**
45+
Note that passing props as spread attribute without `htmlFor` explicitly defined will cause this rule to fail. Explicitly pass down `htmlFor` prop for rule to pass. The prop must have an actual value to pass. Use `Label` component above as a reference. **It is a good thing to explicitly pass props that you expect to be passed for self-documentation.** For example:
46+
#### Bad
47+
```jsx
48+
function Foo(props) {
49+
return <label {...props} />
50+
}
51+
```
52+
53+
#### Good
54+
```jsx
55+
function Foo({ htmlFor, ...props}) {
56+
return <label htmlFor={htmlFor} {...props} />
57+
}
58+
59+
// OR
60+
61+
function Foo(props) {
62+
const {
63+
htmlFor,
64+
...otherProps
65+
} = props;
66+
67+
return <label htmlFor={htmlFor} {...otherProps} />
68+
}
69+
```
4670

4771
### Succeed
4872
```jsx

0 commit comments

Comments
 (0)