|
9 | 9 |
|
10 | 10 | ## Reusable components |
11 | 11 |
|
12 | | -* Do not make a new file for smaller components. |
13 | | -* Smaller, reusable components needed in the main components should be added **above** the main component, **not** inside it. |
14 | | -* Use ES6 arrow functions for defining components. |
| 12 | +- Do not make a new file for smaller components. |
| 13 | +- Smaller, reusable components needed in the main components should be added **above** the main component, **not** inside it. |
| 14 | +- Use ES6 arrow functions for defining components. |
15 | 15 |
|
16 | 16 | ## Spacing |
17 | 17 |
|
18 | 18 | 1. **JS:** |
19 | | - * Use a space after `if`, `for`, `while`, `switch`. |
20 | | - * Do not use a space after the opening `(` and before the closing `)`. |
21 | | - * Use a space before and after destructuring objects. |
22 | | - ```js |
23 | | - //good |
24 | | - const { apple, mangoes } = fruits; |
25 | | - |
26 | | - //bad |
27 | | - const {apple, mangoes} = fruits; |
| 19 | + - Use a space after `if`, `for`, `while`, `switch`. |
| 20 | + - Do not use a space after the opening `(` and before the closing `)`. |
| 21 | + - Use a space before and after destructuring objects. |
| 22 | + ```js |
| 23 | + //good |
| 24 | + const { apple, mangoes } = fruits; |
| 25 | + |
| 26 | + //bad |
| 27 | + const { apple, mangoes } = fruits; |
| 28 | + ``` |
28 | 29 |
|
29 | 30 |
|
30 | 31 | //Same for destructuring props: |
|
36 | 37 | ``` |
37 | 38 |
|
38 | 39 | 2. **JSX:** |
39 | | - * Use a space before the forward slash (`/`) of a self-closing tag |
40 | | - ```js |
41 | | - //good |
42 | | - <Foo /> |
43 | 40 |
|
44 | | - //bad |
45 | | - <Foo/> |
46 | | - ``` |
47 | | - * Do **not** use spaces for JSX curly braces |
48 | | - ```js |
49 | | - //good |
50 | | - <Foo bar={baz} /> |
| 41 | + - Use a space before the forward slash (`/`) of a self-closing tag |
51 | 42 |
|
52 | | - //bad |
53 | | - <Foo bar={ baz } /> |
54 | | - ``` |
| 43 | + ```js |
| 44 | + //good |
| 45 | + <Foo /> |
| 46 | +
|
| 47 | + //bad |
| 48 | + <Foo/> |
| 49 | + ``` |
| 50 | + |
| 51 | + - Do **not** use spaces for JSX curly braces |
| 52 | + |
| 53 | + ```js |
| 54 | + //good |
| 55 | + <Foo bar={baz} /> |
| 56 | + |
| 57 | + //bad |
| 58 | + <Foo bar={ baz } /> |
| 59 | + ``` |
55 | 60 |
|
56 | 61 | ## **Props:** |
57 | 62 |
|
58 | | -* Use camelCase for prop names, or PascalCase if the prop value is a React component. |
59 | | -* Use new lines when props do not fit on the same line. |
60 | | - ```js |
61 | | - //good |
62 | | - <Foo |
63 | | - prop1={value1} |
64 | | - prop2={value2} |
65 | | - prop3={value3} |
66 | | - /> |
67 | | -
|
68 | | - //bad |
69 | | - <Foo prop1={value1} prop2={value2} prop3={value3} /> |
70 | | - ``` |
| 63 | +- Use camelCase for prop names, or PascalCase if the prop value is a React component. |
| 64 | +- Use new lines when props do not fit on the same line. |
| 65 | + |
| 66 | + ```js |
| 67 | + //good |
| 68 | + <Foo |
| 69 | + prop1={value1} |
| 70 | + prop2={value2} |
| 71 | + prop3={value3} |
| 72 | + /> |
| 73 | + |
| 74 | + //bad |
| 75 | + <Foo prop1={value1} prop2={value2} prop3={value3} /> |
| 76 | + ``` |
71 | 77 |
|
72 | 78 | ## **Best practices:** |
73 | 79 |
|
74 | | -* **Always** add semicolons after a line. |
75 | | -* Use ES6 arrow functions. |
76 | | -* Keep the indentation in your code correct. |
77 | | -* Use 4 spaces for tabs. |
78 | | -* Don't Repeat Yourself. If you think you're repeating too much code, make a smaller component, or a function. |
79 | | -* **Always** add alt prop to `img` tags. |
80 | | -* Add `rel="noopener"` for `a` tags which has `target="_blank"`. |
81 | | -* Don't do `outline: none` on user input elements. If you do not want outline, give them faint, visible background on focus. This is for accessibility. |
| 80 | +- **Always** add semicolons after a line. |
| 81 | +- Use ES6 arrow functions. |
| 82 | +- Keep the indentation in your code correct. |
| 83 | +- Use 4 spaces for tabs. |
| 84 | +- Don't Repeat Yourself. If you think you're repeating too much code, make a smaller component, or a function. |
| 85 | +- **Always** add alt prop to `img` tags. |
| 86 | +- Add `rel="noopener"` for `a` tags which has `target="_blank"`. |
| 87 | +- Don't do `outline: none` on user input elements. If you do not want outline, give them faint, visible background on focus. This is for accessibility. |
82 | 88 |
|
83 | 89 | ### Other things to note |
84 | 90 |
|
85 | | -* We are using [octicons](https://primer.style/octicons/) for icons. Use this if you need to add icons. Do **not** add a new library for icons. |
86 | | -* Try to not commit changes in `package.json`, `package-lock.json`. |
87 | | -* Discuss with contributors on discord if you're planning to add/remove a package. |
| 91 | +- We are using [octicons](https://primer.style/octicons/) for icons. Use this if you need to add icons. Do **not** add a new library for icons. |
| 92 | +- Try to not commit changes in `package.json`, `package-lock.json`. |
| 93 | +- Discuss with contributors on discord if you're planning to add/remove a package. |
88 | 94 |
|
89 | 95 | ## Further reading: |
90 | 96 |
|
91 | | -This guide is based on [airbnb's react guide](https://github.com/airbnb/javascript/tree/master/react). You can read all the best practices there. |
| 97 | +This guide is based on [airbnb's react guide](https://github.com/airbnb/javascript/tree/master/react). You can read all the best practices there. |
0 commit comments