You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -875,9 +875,9 @@ If you go to this URL in your browser, you should notice that the code has been
875
875
876
876
Server-side rendering means that your application initially renders the components on the server-side, rather than fetching data from the server and rendering using JavaScript. This enhances the performance of your application since the user will see the initial state immediately.
877
877
878
-
We need to make some motifications to `CommentBox` to support server-side rendering. Firstly, we need to accept an `initialData` prop, which will be used to set the initial state of the component, rather than doing an AJAX request. We also need to ensure the `setInterval` call for polling for new comments is only executed client-side. Finally, we will remove the `loadCommentsFromServer` call from `getInitialState`, since it is no longer required.
878
+
We need to make some motifications to `CommentBox` to support server-side rendering. Firstly, we need to accept an `initialData` prop, which will be used to set the initial state of the component, rather than doing an AJAX request. We also need to ensure the `setInterval` call for polling for new comments is only executed client-side, by moving it to the `componentDidMount` method. Finally, we will remove the `loadCommentsFromServer` call from `getInitialState`, since it is no longer required.
879
879
880
-
```javascript{28,31-35}
880
+
```javascript{28,30-32}
881
881
var CommentBox = React.createClass({
882
882
loadCommentsFromServer: function() {
883
883
var xhr = new XMLHttpRequest();
@@ -907,12 +907,8 @@ var CommentBox = React.createClass({
907
907
getInitialState: function() {
908
908
return { data: this.props.initialData };
909
909
},
910
-
componentWillMount: function() {
911
-
//this.loadCommentsFromServer();
912
-
// Only do this in the browser, not on the server-side.
0 commit comments