I got the below react js cod running with no errors but not sure why it's not displaying anything from the database in the <li> element.
When I console log it in the ComponentWillMount, it pulls the data correctly.
App.js
class FirebaseDB extends React.Component {
constructor(props) {
super(props);
this.state = { messages: [] };
}
componentWillMount(){
let messagesRef = firebase.database().ref('messages');
messagesRef.on('child_added', snapshot => {
let message = { text: snapshot.val(), id: snapshot.key };
console.log(message);
})
}
render() {
return (
<div>
<ul>
{ /* Render the list of messages */
this.state.messages.map( message => <li key={message.id}>{message.text}</li> )
}
</ul>
</div>
);
}
}
class App extends Component {
render() {
return (
<FirebaseDB />
);
}
}