Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions docs/docs/react-without-es6.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ In React components declared as ES6 classes, methods follow the same semantics a
class SayHello extends React.Component {
constructor(props) {
super(props);
this.state = { message: 'Hello!' };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick. FB style is to write it without spaces:

  this.state = {message: 'Hello!'};

We use this style in all other examples so it's best to keep it consistent.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this in a followup commit.

// This line is important!
this.handleClick = this.handleClick.bind(this);
}

handleClick() {
alert('Hello!');
alert(this.state.message);
}

render() {
Expand All @@ -120,8 +121,12 @@ With `React.createClass()`, this is not necessary because it binds all methods:

```javascript
var SayHello = React.createClass({
getInitialState: function() {
return { message: 'Hello!' };
},

handleClick: function() {
alert('Hello!');
alert(this.state.message);
},

render: function() {
Expand All @@ -141,10 +146,14 @@ If the boilerplate code is too unattractive to you, you may enable the **experim

```javascript
class SayHello extends React.Component {
constructor(props) {
super(props);
this.state = { message: 'Hello!' };
}
// WARNING: this syntax is experimental!
// Using an arrow here binds the method:
handleClick = () => {
alert('Hello!');
alert(this.state.message);
}

render() {
Expand Down