Created
May 26, 2018 16:32
-
-
Save ipassynk/3c737f8948b9b78fa7aa566c9fe8629d to your computer and use it in GitHub Desktop.
React Firebase Map/Filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from 'react'; | |
import logo from './logo.svg'; | |
import './App.css'; | |
import firebase from 'firebase'; | |
class App extends Component { | |
constructor(props) { | |
super(props); | |
var config = { | |
apiKey: "AIzaSyCkzZrgacyb6wVpmhCyl0ww8gBY5z0EHg8", | |
authDomain: "react-cool.firebaseapp.com", | |
databaseURL: "https://react-cool.firebaseio.com", | |
projectId: "react-cool", | |
storageBucket: "react-cool.appspot.com", | |
messagingSenderId: "974569918115" | |
}; | |
firebase.initializeApp(config); | |
const fireBaseRef = firebase.database().ref('messages'); | |
fireBaseRef.on('value', snapshot => { | |
const messages = snapshot.val(); | |
const middleAgePeople = messages.filter(({age}) => age> 30).map(({name, age}) => `${name} is ${age} old`); | |
console.log(middleAgePeople); | |
this.setState({ | |
messages | |
}) | |
}); | |
} | |
render() { | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<img src={logo} className="App-logo" alt="logo"/> | |
<h1 className="App-title">Welcome to React</h1> | |
</header> | |
<p className="App-intro"> | |
To get started, edit <code>src/App.js</code> and save to reload. | |
</p> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment