Skip to content
Closed
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
24 changes: 18 additions & 6 deletions docs/docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ var CommentBox = React.createClass({

The key is the call to `this.setState()`. We replace the old array of comments with the new one from the server and the UI automatically updates itself. Because of this reactivity, it is trivial to add live updates. We will use simple polling here but you could easily use WebSockets or other technologies.

```javascript{3,17-21,35}
```javascript{3,17-21,38}
// tutorial14.js
var CommentBox = React.createClass({
loadCommentsFromServer: function() {
Expand All @@ -412,11 +412,14 @@ var CommentBox = React.createClass({
},
componentWillMount: function() {
this.loadCommentsFromServer();
setInterval(
this.intervalID = setInterval(
this.loadCommentsFromServer.bind(this),
this.props.pollInterval
);
},
componentWillUnmount: function() {
clearInterval(this.intervalID);
},
render: function() {
return (
<div class="commentBox">
Expand Down Expand Up @@ -501,7 +504,7 @@ When a user submits a comment, we will need to refresh the list of comments to i

We need to pass data from the child component to its parent. We do this by passing a `callback` in props from parent to child:

```javascript{13-15,30}
```javascript{13-15,33}
// tutorial17.js
var CommentBox = React.createClass({
loadCommentsFromServer: function() {
Expand All @@ -522,11 +525,14 @@ var CommentBox = React.createClass({
},
componentWillMount: function() {
this.loadCommentsFromServer();
setInterval(
this.intervalID = setInterval(
this.loadCommentsFromServer.bind(this),
this.props.pollInterval
);
},
componentWillUnmount: function() {
clearInterval(this.intervalID);
},
render: function() {
return (
<div class="commentBox">
Expand Down Expand Up @@ -599,11 +605,14 @@ var CommentBox = React.createClass({
},
componentWillMount: function() {
this.loadCommentsFromServer();
setInterval(
this.intervalID = setInterval(
this.loadCommentsFromServer.bind(this),
this.props.pollInterval
);
},
componentWillUnmount: function() {
clearInterval(this.intervalID);
},
render: function() {
return (
<div class="commentBox">
Expand Down Expand Up @@ -654,11 +663,14 @@ var CommentBox = React.createClass({
},
componentWillMount: function() {
this.loadCommentsFromServer();
setInterval(
this.intervalID = setInterval(
this.loadCommentsFromServer.bind(this),
this.props.pollInterval
);
},
componentWillUnmount: function() {
clearInterval(this.intervalID);
},
render: function() {
return (
<div class="commentBox">
Expand Down