When i want to display data from firestore in node.js, i get an error on this code: productsContainer.appendChild(article);
With this error: Firestore Uncaught (in promise) TypeError: Cannot read property 'appendChild' of null
const myProducts = db.collection('products').doc('fruit');
const productsContainer = document.querySelector('#groceries');
function renderProduct(data) {
const docFrag = document.createDocumentFragment();
let article = document.createElement('article');
let productName = document.createElement('h4');
let productPrice = document.createElement('p');
article.setAttribute('id', data.id);
productName.textContent = data.name;
productPrice.textContent = data.price;
docFrag.appendChild(productName);
docFrag.appendChild(productPrice);
article.appendChild(docFrag);
productsContainer.appendChild(article);
}
myProducts.get().then(function(documentSnapshot) {
if (documentSnapshot.exists) {
var products = documentSnapshot.data();
console.log(products);
renderProduct(products);
}
});
class contact extends React.Component {
render() {
return (
<div className="app-wrapper">
<ContainerHeader match={this.props.match} title={<IntlMessages id="appModule.contactSupport"/>}/>
<div className="d-flex justify-content-center">
<div id="groceries"></div>
</div>
</div>
);
}
}