I have a React component that connects to Firebase to receive data. I'm able to connect and get the data I'd like to use to log out to the console, but I'm unable to return it with HTML. In fact, the HTML returns "01". Can anyone tell me why the data is showing up in the console but not the page, and the 01 is being displayed in the browser?
/* eslint-disable */
import React, { Component } from "react";
import firebase from "./Firebase";
class ActiveProjects extends Component {
constructor(props) {
super(props);
this.state = {
isLoaded: false,
projects: []
};
}
componentDidMount() {
const db = firebase.firestore();
db.collection("projects")
.get()
.then(querySnapshot => {
const data = querySnapshot.docs.map(doc => doc.data());
data.forEach(cur_doc => {
this.state.projects.push({ ...cur_doc });
});
})
.then(result => {
this.setState({ isLoaded: true });
});
}
render() {
const { isLoaded, projects } = this.state;
if (!isLoaded) {
return <div>Loading...</div>;
} else {
return (
<div>
{Object.keys(
projects.map((proj, index) => (
<div>
<h2>{proj["description"]}</h2>
{console.log(index)}{console.log(proj["description"])}
//Output
// 0
// This is some text for the description.
// 1
// My description text.
</div>
))
)}
</div>
);
}
}
}
export default ActiveProjects;