diff --git a/docs/docs/tutorial.md b/docs/docs/tutorial.md index ddeae78aa8a89..117f5c8149584 100644 --- a/docs/docs/tutorial.md +++ b/docs/docs/tutorial.md @@ -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() { @@ -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 (
@@ -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() { @@ -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 (
@@ -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 (
@@ -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 (