Prechádzať zdrojové kódy

Listing 12: initial state with setInitialState().

Frederic G. MARAND 8 rokov pred
rodič
commit
99745abe3a
1 zmenil súbory, kde vykonal 4 pridanie a 1 odobranie
  1. 4 1
      public/scripts/tutorial.js

+ 4 - 1
public/scripts/tutorial.js

@@ -48,11 +48,14 @@ let CommentForm = React.createClass({
 });
 
 let CommentBox = React.createClass({
+  getInitialState: function () {
+    return { data: [] };
+  },
   render: function () {
     return (
       <div className="commentBox">
         <h1>Comments</h1>
-        <CommentList data={this.props.data} />
+        <CommentList data={this.state.data} />
         <CommentForm />
         </div>
     );