Skip to content

Instantly share code, notes, and snippets.

@mfsiat
Last active August 28, 2019 17:56
Show Gist options
  • Save mfsiat/f617e45b43f9d22451eb82a412423e72 to your computer and use it in GitHub Desktop.
Save mfsiat/f617e45b43f9d22451eb82a412423e72 to your computer and use it in GitHub Desktop.
render() {
return (
<View >
<View >
<FlatList
data = {this.state.busLists}
renderItem = {({item}) => (
<View>
<Text>{item}</Text>
</View>
)}
/>
</View>
</View>
);
}
}
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