I'm learning react without redux, mobx or any other libraries. The reason why I don't use redux, and so on is that someone told me that it is important to get use to react before using libraries. I'm trying to get data from firestore and render it, but because of async, I'm stuck to render data. I can't render because I don't get data when I render.
My react version is 16 and I practice react with firestore. Here's my code.
I'll appreciate you whatever you give me your advice. Thank you.
CategoryButtonSet.js
import React from 'react';
import CategoryButton from './CategoryButton';
import {test} from '../shared/Firebase';
export default class CategoryButtonSet extends React.Component {
categories = [];
componentDidMount() {
test().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
this.categories.push(doc.id).bind(this);
});
});
}
render() {
if(this.categories.length !== 0) {
console.log(this.categories);
return (
<div className="category-block">
This block is for the category button set.
{
this.categories.map(category => <CategoryButton key={category} name={category}/>)
}
</div>
);
} else {
return <div>Loading...</div>;
}
}
}
CategoryButton.js
import React from 'react';
export default (props) => {
return (
<div className="category-block__button">
Here's the category button.
<button>{props.name}</button>
</div>
);
}