Commit fd1e5477 authored by Alexander Kotov's avatar Alexander Kotov

lead messages from firebase

parent db452c7a
......@@ -7,22 +7,11 @@ import MessageForm from './components/MessageForm';
import authWithGoogle from './authWithGoogle';
import firebase from './firebase'
const database = firebase.database()
class App extends Component {
state = {
messages: [
{
body: 'Welcome',
author: 'Alexander Kotov'
},
{
body: 'Hi',
author: 'Dima'
},
{
body: 'Cool!',
author: 'Taras'
}
]
messages: []
}
componentDidMount() {
......@@ -34,16 +23,23 @@ class App extends Component {
}
this.setState({ user });
})
let messagesRef = database.ref('messages')
messagesRef.on('child_added', data => {
let message = data.val()
this.addMessage(message)
})
}
sendMessage = (message) => {
}
addMessage(message) {
this.setState({
messages: [
...this.state.messages,
{
...message,
author: this.state.user.name
}
message
]
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment