I'm trying to start with React, following the example on firebaseBlog, I tried running the following piece of code, I get,
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());
And the code being referred to is this.
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)
);
}
If your component declaration extends React.Component, like so ...
then your componentWillMount(), and other functions should be like this ...