Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Step 3: Using the Sanity Client to get all product data and display t…
Browse files Browse the repository at this point in the history
…hem on the page
  • Loading branch information
colbyfayock committed Jan 18, 2021
1 parent 72d1139 commit 167b089
Showing 1 changed file with 21 additions and 28 deletions.
49 changes: 21 additions & 28 deletions pages/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import Head from 'next/head'

import { client } from '../lib/sanity';

import styles from '../styles/Home.module.css'

export default function Home() {
export default function Home({ products }) {
return (
<div className={styles.container}>
<Head>
Expand All @@ -20,33 +23,14 @@ export default function Home() {
</p>

<div className={styles.grid}>
<a href="https://nextjs.org/docs" className={styles.card}>
<h3>Documentation &rarr;</h3>
<p>Find in-depth information about Next.js features and API.</p>
</a>

<a href="https://nextjs.org/learn" className={styles.card}>
<h3>Learn &rarr;</h3>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a>

<a
href="https://github.com/vercel/next.js/tree/master/examples"
className={styles.card}
>
<h3>Examples &rarr;</h3>
<p>Discover and deploy boilerplate example Next.js projects.</p>
</a>

<a
href="https://vercel.com/import?filter=next.js&utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
className={styles.card}
>
<h3>Deploy &rarr;</h3>
<p>
Instantly deploy your Next.js site to a public URL with Vercel.
</p>
</a>
{products.map(product => {
return (
<a key={product._id} href="#" className={styles.card}>
<h3>{ product.title }</h3>
<p>{ product.blurb.en }</p>
</a>
)
})}
</div>
</main>

Expand All @@ -63,3 +47,12 @@ export default function Home() {
</div>
)
}

export async function getStaticProps() {
const products = await client.fetch(`*[_type == "product"]`);
return {
props: {
products
}
}
}

0 comments on commit 167b089

Please sign in to comment.