@@ -8,9 +8,10 @@ Thanks to [AirBNB](AirBNB) for heavily inspiring this document.
8
8
## How to Update This
9
9
10
10
To update this document, make a pull request with your recommended changes. The
11
- pull request must receive a thumbs up emoji (👍) from at least half the active
12
- dev team prior to merging. The pull request itself can be used for discussion,
13
- comments, and iteration on the proposed change.
11
+ pull request must receive ** an approved review** from at least half the active
12
+ development team prior to merging. The pull request itself can be used for
13
+ discussion, comments, and iteration on the proposed change. To ensure others
14
+ are notified, please request reviews from appropriate developers.
14
15
15
16
Rules here should be 1) actionable and 2) clearly testable in a PR review.
16
17
45
46
- Use a line length of 80 characters.
46
47
- Use camelCase when naming objects, functions, and instances.
47
48
48
- ``` jsx
49
+ ``` javascript
49
50
// bad
50
51
const UsTaxes = 1000
51
52
const playerID = 10
@@ -62,7 +63,7 @@ function getUnescoProperties() {}
62
63
63
64
- Use PascalCase when naming constructors, classes, and components.
64
65
65
- ``` jsx
66
+ ``` javascript
66
67
// bad
67
68
const myContainer = styled .div `
68
69
color: blue;
@@ -76,7 +77,7 @@ const MyContainer = styled.div`
76
77
77
78
- Group your shorthand properties at the end of your object declaration.
78
79
79
- ``` jsx
80
+ ``` javascript
80
81
const anakinSkywalker = ' Anakin Skywalker'
81
82
const lukeSkywalker = ' Luke Skywalker'
82
83
@@ -106,7 +107,7 @@ const obj = {
106
107
- An exception to this is arrow functions, which must be assigned to
107
108
variables.
108
109
109
- ``` jsx
110
+ ``` javascript
110
111
// bad
111
112
const foo = function () {
112
113
// ...
@@ -120,7 +121,7 @@ function foo() {
120
121
121
122
- Never declare functions inside blocks. This might work but is invalid JS.
122
123
123
- ``` jsx
124
+ ``` javascript
124
125
// bad
125
126
if (currentUser) {
126
127
function test () {
@@ -139,7 +140,7 @@ if (currentUser) {
139
140
140
141
- Always put default parameters last.
141
142
142
- ``` jsx
143
+ ``` javascript
143
144
// bad
144
145
function handleThings (opts = {}, name ) {
145
146
// ...
@@ -158,7 +159,7 @@ function handleThings(name, opts = {}) {
158
159
UPPERCASE_VARIABLES are letting the programmer know that they can trust
159
160
the variable (and its properties) not to change.
160
161
161
- ``` jsx
162
+ ``` javascript
162
163
// bad
163
164
export const THING_TO_BE_CHANGED = ' should obviously not be uppercased'
164
165
@@ -183,7 +184,7 @@ export const API_KEY = 'SOMEKEY'
183
184
- Use the ` .stories.js ` and ` test.js ` extensions for stories and tests where
184
185
applicable.
185
186
186
- ``` jsx
187
+ ```
187
188
// bad
188
189
./MyComponent.js
189
190
./test/MyComponent.js
@@ -221,14 +222,54 @@ export const API_KEY = 'SOMEKEY'
221
222
- We initialize our web applications with create-react-app.
222
223
- Next.js and Gatsby are also acceptable.
223
224
- Use hooks instead of other state management.
225
+ - Use functional components over class components.
226
+
227
+ ``` jsx
228
+ // bad
229
+ class Welcome extends React .Component {
230
+ render () {
231
+ const greeting = getGreeting ()
232
+ return < h1> {greeting}< / h1>
233
+ }
234
+ }
235
+
236
+ // good
237
+ function Welcome () {
238
+ const greeting = getGreeting ()
239
+ return < h1> {greeting}< / h1>
240
+ }
241
+ ```
242
+
243
+ - Use named functions over arrow functions unless using an implicit return.
244
+
245
+ ``` jsx
246
+ // bad
247
+ const Welcome = () => {
248
+ const greeting = getGreeting ()
249
+ return (
250
+ < h1> {greeting}< / h1>
251
+ )
252
+ }
253
+
254
+ // good
255
+ function Welcome () {
256
+ const greeting = getGreeting ()
257
+ return < h1> {greeting}< / h1>
258
+ }
259
+
260
+ // good
261
+ const Welcome = () => (
262
+ < h1> {getGreeting ()}< / h1>
263
+ )
264
+ ```
224
265
225
266
## Component Driven Development
226
267
227
268
- Practice CDD with Storybook in React applications.
228
269
- All component stories should have a ` Default ` state.
229
270
- Put spaces in story component names for consistency with story parsing.
230
271
231
- ``` graphql
272
+ ``` javascript
232
273
// bad
233
274
export default {
234
275
title: ' pages/BrowsePage' ,
0 commit comments