I took the data in firebase and setState, this.state.data array is stamped with 0.
I do not know why, I need your help.
constructor() {
super();
this.state = {
data:[],
}
}
componentDidMount(){
this.getData();
}
getData(){
const arrayItem = [];
firebase.database().ref('data').on('value', (snapshot) =>{
snapshot.forEach(function(childSnap){
arrayItem.push({
key:childSnap.key,
data:childSnap.val()
})
})
})
this.setState({
data:arrayItem
})
}
render() {
{console.log(this.state.data)}
