Last active
August 28, 2019 17:56
-
-
Save mfsiat/f617e45b43f9d22451eb82a412423e72 to your computer and use it in GitHub Desktop.
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
render() { | |
return ( | |
<View > | |
<View > | |
<FlatList | |
data = {this.state.busLists} | |
renderItem = {({item}) => ( | |
<View> | |
<Text>{item}</Text> | |
</View> | |
)} | |
/> | |
</View> | |
</View> | |
); | |
} | |
} |
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
constructor(props) { | |
super(props); | |
this.state = ({ | |
busList: '', | |
busLists: [] | |
}) | |
} | |
componentDidMount() { | |
firebase.database().ref().child('busList/').once('value', snapshot => { | |
const data = snapshot.val() | |
if(snapshot.val()) { | |
const initMessages = []; | |
Object.keys(data).forEach(busList => initMessages.push(data[busList])); | |
this.setState({ | |
busLists: initMessages | |
}) | |
} | |
}) | |
firebase.database().ref().child('busList/').on("child_added", snapshot =>{ | |
const data = snapshot.val(); | |
if(data) { | |
this.setState(prevState => ({ | |
busLists: [data, ...prevState.busLists] | |
})) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment