I have this block of code
class PaintingPage extends Component {
constructor(props){
super(props)
this.state = {
paintings: []
}
this.database = this.database.bind(this);
}
database = () => {
let db = fire.firestore();
db.collection('PaintingProjects')
.get()
.then( snapshot => {
let paintingData = [];
snapshot.forEach( doc => {
const data = doc.data()
paintingData.push(data);
console.log(paintingData, '1st')
this.setState({
paintings: paintingData,
})
console.log(this.paintings, '2nd')
})
})
}
componentWillMount(){
this.database()
}
I'm trying to save my PaintingProjects collection to my state. When I log the paintingData array all of my data is there but after I save it to my state and log my state its comes back as undefinied what am I doing wrong?