You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add rule to avoid misusing DOM component prop names
People expect props like `style` and `className` to mean one specific
thing. Varying this API for a subset of your app makes the code less
readable and less maintainable, and may cause bugs.
Copy file name to clipboardExpand all lines: react/README.md
+13Lines changed: 13 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -127,6 +127,19 @@
127
127
return WithFoo;
128
128
}
129
129
```
130
+
131
+
-**Props Naming**: Avoid using DOM component prop names for different purposes.
132
+
133
+
> Why? People expect props like `style` and `className` to mean one specific thing. VaryingthisAPIfor a subset of your app makes the code less readable and less maintainable, and may cause bugs.
134
+
135
+
```jsx
136
+
// bad
137
+
<MyComponent style="fancy" />
138
+
139
+
// good
140
+
<MyComponent variant="fancy" />
141
+
```
142
+
130
143
## Declaration
131
144
132
145
- Do not use `displayName`for naming components. Instead, name the component by reference.
0 commit comments