-
Notifications
You must be signed in to change notification settings - Fork 26.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor cleanup for the React styleguide #619
Conversation
@@ -69,13 +69,13 @@ | |||
**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: | |||
```javascript | |||
// bad | |||
const Footer = require('./Footer/Footer.jsx') | |||
import Footer from './Footer/Footer.jsx'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we omit the extension in all our examples? file extensions should ideally never be specified in a require
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ljharb 👍
<button onClick={handleClick}>Click me</button>
│ │
│ └─ (verb) component's action
└─ (noun) component's property In many cases the event handlers (actions) should be named so that it's easy to understand what a particular function is doing. For example: <button onClick={pokePlayer}>Poke Player</button>
│ │
│ └─ (verb) a function performing a specific action
└─ (noun) a property holding a reference to the component's action(s) In both these examples using the |
That is a pretty convincing counterpoint. |
The one issue with that is it makes the |
That is true. However, I'm not convinced we want to retain that rule (obv it'll need further discussion) |
I'm happy to drop that from this PR and leave it for another conversation. |
@kesne yeah let's split the naming section into a separate PR, and keep the rule fix and the rest of the guide cleanups? |
I think we should use arrow functions instead of // bad
class extends React.Component {
constructor(props) {
super(props);
this.onClickDiv = this.onClickDiv.bind(this);
}
onClickDiv() {
// do stuff
}
render() {
return <div onClick={this.onClickDiv} />
}
}
// good
class extends React.Component {
constructor(props) {
super(props);
}
onClickDiv = () => {
// do stuff
}
render() {
return <div onClick={this.onClickDiv} />
}
} |
@charpeni That would require the class properties proposal, which we don't yet use at Airbnb because it's too far from being finalized. |
It's actually not even ES7 😭 |
@ljharb I did not noticed that class properties was only a proposal, thank you for the clarification. |
e587336
to
1f65662
Compare
LGTM pending one final rebase. (This is a breaking change, fwiw) |
1f65662
to
e12e5f0
Compare
[eslint config] [breaking] [react] Minor cleanup for the React styleguide
This fixes some minor things that I thought were missing from the styleguide.
If people are unhappy about enforcing names for event handlers or additional render methods, I'm happy to discuss/remove.
true
props.