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 (