rsnext/examples/with-mysql/pages/index.js
Lee Robinson fe312ed4bd
Update MySQL example. (#34784)
Changes from https://github.com/planetscale/nextjs-starter.

Realized the current example was not only out of date, but the demo was broken. Will update the demo site post-merge here 👍
2022-02-25 03:41:41 +00:00

46 lines
1.2 KiB
JavaScript

import Head from 'next/head'
import Product from '../components/Product'
import prisma from '../lib/prisma'
export default function Home({ products }) {
return (
<div>
<Head>
<title>PlanetScale Next.js Quickstart</title>
<meta name="description" content="PlanetScale Quickstart for Next.js" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main className="p-10 mx-auto max-w-4xl">
<h1 className="text-6xl font-bold mb-4 text-center">Next.js Starter</h1>
<p className="mb-20 text-xl text-center">
🔥 Shop from the hottest items in the world 🔥
</p>
<div className="grid md:grid-cols-3 sm:grid-cols-2 grid-cols-1 justify-items-center gap-4">
{products.map((product) => (
<Product product={product} key={product.id} />
))}
</div>
</main>
<footer></footer>
</div>
)
}
export async function getStaticProps(context) {
const data = await prisma.product.findMany({
include: {
category: true,
},
})
//convert decimal value to string to pass through as json
const products = data.map((product) => ({
...product,
price: product.price.toString(),
}))
return {
props: { products },
}
}