Skip to content

Commit 38d2282

Browse files
committed
Merge pull request airbnb#374 from airbnb/horace/jsx-ext-for-react
Recommend using .jsx extension for React components, rather than .js
2 parents 128cb7b + d2792f2 commit 38d2282

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

react/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
## Naming
2626

27-
- **Extensions**: Use `.js` extension for React components.
28-
- **Filename**: Use PascalCase for filenames. E.g., `ReservationCard.js`.
27+
- **Extensions**: Use `.jsx` extension for React components.
28+
- **Filename**: Use PascalCase for filenames. E.g., `ReservationCard.jsx`.
2929
- **Reference Naming**: Use PascalCase for React components and camelCase for their instances:
3030
```javascript
3131
// bad
@@ -41,21 +41,21 @@
4141
const reservationItem = <ReservationCard />;
4242
```
4343

44-
**Component Naming**: Use the filename as the component name. So `ReservationCard.js` should have a reference name of ReservationCard. However, for root components of a directory, use index.js as the filename and use the directory name as the component name:
44+
**Component Naming**: Use the filename as the component name. For example, `ReservationCard.jsx` should have a reference name of `ReservationCard`. However, for root components of a directory, use `index.jsx` as the filename and use the directory name as the component name:
4545
```javascript
4646
// bad
47-
const Footer = require('./Footer/Footer.js')
47+
const Footer = require('./Footer/Footer.jsx')
4848
4949
// bad
50-
const Footer = require('./Footer/index.js')
50+
const Footer = require('./Footer/index.jsx')
5151
5252
// good
5353
const Footer = require('./Footer')
5454
```
5555

5656

5757
## Declaration
58-
- Do not use displayName for naming components, instead name the component by reference.
58+
- Do not use displayName for naming components. Instead, name the component by reference.
5959

6060
```javascript
6161
// bad
@@ -72,7 +72,7 @@
7272
```
7373

7474
## Alignment
75-
- Follow these alignment styles for js syntax
75+
- Follow these alignment styles for JS syntax
7676

7777
```javascript
7878
// bad
@@ -98,7 +98,7 @@
9898
```
9999

100100
## Quotes
101-
- Always use double quotes (`"`) for JSX attributes, but single quotes for all other JavaScript.
101+
- Always use double quotes (`"`) for JSX attributes, but single quotes for all other JS.
102102
```javascript
103103
// bad
104104
<Foo bar='bar' />
@@ -197,7 +197,7 @@
197197
```
198198

199199
## Methods
200-
- Do not use underscore prefix for internal methods of a react component.
200+
- Do not use underscore prefix for internal methods of a React component.
201201
```javascript
202202
// bad
203203
React.createClass({
@@ -219,10 +219,10 @@
219219
```
220220

221221
## Ordering
222-
- Always follow the following order for methods in a react component:
222+
- Always follow the following order for methods in a React component:
223223

224224
1. displayName
225-
2. mixins (as of React v0.13 mixins are deprecated)
225+
2. mixins (as of React v0.13, mixins are deprecated)
226226
3. statics
227227
4. propTypes
228228
5. getDefaultProps

0 commit comments

Comments
 (0)