Skip to content

Instantly share code, notes, and snippets.

@ehrudxo
Created July 3, 2016 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehrudxo/822b121cd680a23cf6cf6d704d6f505f to your computer and use it in GitHub Desktop.
Save ehrudxo/822b121cd680a23cf6cf6d704d6f505f to your computer and use it in GitHub Desktop.
some part of airbnb react style guide
// bad
const Listing = React.createClass({
// ...
render() {
return <div>{this.state.hello}</div>;
}
});
// good
class Listing extends React.Component {
// ...
render() {
return <div>{this.state.hello}</div>;
}
}
/**
* React.createClass 와 ES2015 중 후자를 선택했네요.
* 그 이유는 공개하지 않았지만, 장기적으로 코드가 ES2015로 대부분 갈 것이고
* 코드 가독성 면에서의 장점으로 선택하지 않았을까 생각해 봅니다.
*
* 또 stateless function 이라고 표현한 세번째 방법에 대해서는
* 다음과 같은 철학을 가지고 있네요.
* */
// bad
class Listing extends React.Component {
render() {
return <div>{this.props.hello}</div>;
}
}
// bad (relying on function name inference is discouraged)
const Listing = ({ hello }) => (
<div>{hello}</div>
);
// good
function Listing({ hello }) {
return <div>{hello}</div>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment