How can i set state inside react component?
I`ve got error message:
Uncaught TypeError: Cannot read property 'setState' of null
here is the component code listing:
class MessageList extends React.Component {
 constructor(props){
 super(props);
 this.state = {
   messages: []
 };
 var firebaseRef = firebase.database().ref();
 firebaseRef.once('value')
  .then(function(dataSnapshot) {
      this.setState({
        messages: messages
      });
   });
 }
 render() { ... }
}
 
     
     
    