2017-02-18 9 views
0

私は開始しようとしているがfirebaseBlog上の例以下、反応して、私は次のコードを実行してみました、私はReactFire:Uncaught SyntaxError:予期しないトークン| componentWillMount

Uncaught SyntaxError: http://localhost/h/js/test.js: Unexpected token (1:28) 
> 1 | componentWillMount: function() { 
    |       ^
    2 |   this.firebaseRef = firebase.database().ref("items"); 
    3 |   this.firebaseRef.on("child_added", function(dataSnapshot) { 
    4 |    this.items.push(dataSnapshot.val()); 

、取得し、コードがこれであるために呼ばれています。

componentWillMount: function() { 
     this.firebaseRef = firebase.database().ref("items"); 
     this.firebaseRef.on("child_added", function(dataSnapshot) { 
       this.items.push(dataSnapshot.val()); 
       this.setState({items: this.items}); 
      }.bind(this) 
     ); 
    } 
+1

'firebaseBlog'の例は、より具体的に、どういう例ですか?このスニペットは有効な反応コンポーネントの一部ですが、残りのコンポーネント宣言はまだ必要です。 – loganfsmyth

答えて

0

コンポーネント宣言がそのように...

class TestComponent extends React.Component { 
    ... 
} 

あなたcomponentWillMount()のように、React.Componentを拡張し、他の機能と、このようにする必要があり...

componentWillMount() { 
    ... 
} 
関連する問題