Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

using async/await to implement getInitialProps #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,40 @@ import Information from '../components/Information.js'
import {loadFirebase} from '../lib/db.js'

export default class Index extends React.Component {
static getInitialProps = () =>
loadFirebase().firestore().collection('agencies')
static getInitialProps = async () => {
const snapshot = await loadFirebase().firestore().collection('agencies')
.limit(10)
.get()
.then(snapshot => {
let data = []
snapshot.forEach((doc) => {
data.push({
id: doc.id,
...doc.data()
})
})
return { agencies: data }
let data = []
snapshot.forEach((doc) => {
data.push({
id: doc.id,
...doc.data()
})
})
return { agencies: data }
}
render() {
const agencies = this.props.agencies
return <Layout>
<Hero/>
<div id="agencies">
<h2>Most trusted agencies in Stockholm</h2>
<p>We the brand asked for offers for our
Sample Real Project and had an extra round of
design fixes - that's our way of ranking these
<p>We the brand asked for offers for our
Sample Real Project and had an extra round of
design fixes - that's our way of ranking these
agencies.</p>
{(agencies && agencies.length > 0)
{(agencies && agencies.length > 0)
? <ul>
{agencies.map(agency =>
{agencies.map(agency =>
<li key="{agency.id}">
<h3>{agency.name} has a ranking of
<h3>{agency.name} has a ranking of
<em>{agency.ranking}!</em></h3></li>)}
</ul>
</ul>
: <p><strong>Have nothing!!</strong></p>}
<hr/>
<hr/>
</div>
<Information/>
<Information/>
</Layout>
}
}