I want to return my app as soon as data has been fetched. As long as it hasn't been, I want to display a black screen. Therefore I tried to return JSX after fetching the data, but I get the following error:
Functions are not valid as a React child. This may happen if you return a Component instead of from render. Or maybe you meant to call this function rather than return it.
function App() {
return firebase.firestore().collection('projects').onSnapshot(snap => {
let projects = [];
snap.forEach(doc => {
projects.push(doc.data())
});
return (
<div className="App">
<Router history={history}>
<ScrollToTop>
<Header/>
<Route path="/project/:name" component={Project}/>
<Route path="/about" component={About}/>
<div className="hs">
<Route path={["/", "/project/:name"]} exact component={() => <CartHolder projects={projects}/>}/>
</div>
<div className="hs-mobile">
<Route path="/" exact component={CartHolderMobile}/>
</div>
</ScrollToTop>
</Router>
</div>
);
});
}
What's the best way to do so?