The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
run prettier over next.js 13 server components example
Jon Meyers0e3b20d84719
diff --git a/examples/caching/with-nextjs-13-server-components/app/client-side/page.tsx b/examples/caching/with-nextjs-13-server-components/app/client-side/page.tsxindex 23f8262c143..519b2939626 100644--- a/examples/caching/with-nextjs-13-server-components/app/client-side/page.tsx+++ b/examples/caching/with-nextjs-13-server-components/app/client-side/page.tsx@@ -1,25 +1,21 @@-"use client";+'use client'-import { useEffect, useState } from "react";-import supabase from "../../utils/supabase";+import { useEffect, useState } from 'react'+import supabase from '../../utils/supabase'export default function ClientPosts() {- const [isLoading, setIsLoading] = useState(true);- const [posts, setPosts] = useState<any>([]);+ const [isLoading, setIsLoading] = useState(true)+ const [posts, setPosts] = useState<any>([])useEffect(() => {const fetchPosts = async () => {- const { data } = await supabase.from("posts").select();- setPosts(data);- setIsLoading(false);- };+ const { data } = await supabase.from('posts').select()+ setPosts(data)+ setIsLoading(false)+ }- fetchPosts();- }, []);+ fetchPosts()+ }, [])- return isLoading ? (- <p>Loading</p>- ) : (- <pre>{JSON.stringify(posts, null, 2)}</pre>- );+ return isLoading ? <p>Loading</p> : <pre>{JSON.stringify(posts, null, 2)}</pre>}diff --git a/examples/caching/with-nextjs-13-server-components/app/globals.css b/examples/caching/with-nextjs-13-server-components/app/globals.cssindex 4f1842163d2..36aac7e73df 100644--- a/examples/caching/with-nextjs-13-server-components/app/globals.css+++ b/examples/caching/with-nextjs-13-server-components/app/globals.css@@ -2,8 +2,8 @@ html,body {padding: 0;margin: 0;- font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,- Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;+ font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell,+ Fira Sans, Droid Sans, Helvetica Neue, sans-serif;}a {diff --git a/examples/caching/with-nextjs-13-server-components/app/layout.tsx b/examples/caching/with-nextjs-13-server-components/app/layout.tsxindex 245bd756ae5..24b2aca547f 100644--- a/examples/caching/with-nextjs-13-server-components/app/layout.tsx+++ b/examples/caching/with-nextjs-13-server-components/app/layout.tsx@@ -1,10 +1,6 @@import './globals.css'-export default function RootLayout({- children,-}: {- children: React.ReactNode-}) {+export default function RootLayout({ children }: { children: React.ReactNode }) {return (<html lang="en">{/*diff --git a/examples/caching/with-nextjs-13-server-components/app/page.tsx b/examples/caching/with-nextjs-13-server-components/app/page.tsxindex 35bd2649d4c..951caeb2dc8 100644--- a/examples/caching/with-nextjs-13-server-components/app/page.tsx+++ b/examples/caching/with-nextjs-13-server-components/app/page.tsx@@ -10,8 +10,7 @@ export default function Home() {</h1><p className={styles.description}>- Get started by editing{' '}- <code className={styles.code}>app/page.tsx</code>+ Get started by editing <code className={styles.code}>app/page.tsx</code></p><div className={styles.grid}>@@ -20,10 +19,7 @@ export default function Home() {<p>Find in-depth information about Next.js 13</p></a>- <a- href="https://github.com/vercel/next.js/tree/canary/examples"- className={styles.card}- >+ <a href="https://github.com/vercel/next.js/tree/canary/examples" className={styles.card}><h2>Examples →</h2><p>Explore the Next.js 13 playground.</p></a>diff --git a/examples/caching/with-nextjs-13-server-components/app/realtime/page.tsx b/examples/caching/with-nextjs-13-server-components/app/realtime/page.tsxindex 0b40236e22b..c14ed5303bb 100644--- a/examples/caching/with-nextjs-13-server-components/app/realtime/page.tsx+++ b/examples/caching/with-nextjs-13-server-components/app/realtime/page.tsx@@ -1,16 +1,16 @@-import supabase from "../../utils/supabase";-import RealtimePosts from "./realtime-posts";+import supabase from '../../utils/supabase'+import RealtimePosts from './realtime-posts'// do not cache this page-export const revalidate = 0;+export const revalidate = 0// this component fetches the current posts server-side// and subscribes to new posts client-sideexport default async function Realtime() {- const { data } = await supabase.from("posts").select("*");+ const { data } = await supabase.from('posts').select('*')// data can be passed from server components to client components// this allows us to fetch the initial posts before rendering the page// our <RealtimePosts /> component will then subscribe to new posts client-side- return <RealtimePosts serverPosts={data} />;+ return <RealtimePosts serverPosts={data} />}diff --git a/examples/caching/with-nextjs-13-server-components/app/realtime/realtime-posts.tsx b/examples/caching/with-nextjs-13-server-components/app/realtime/realtime-posts.tsxindex 358c27673de..551c57dcea1 100644--- a/examples/caching/with-nextjs-13-server-components/app/realtime/realtime-posts.tsx+++ b/examples/caching/with-nextjs-13-server-components/app/realtime/realtime-posts.tsx@@ -1,36 +1,34 @@-"use client";+'use client'-import { useEffect, useState } from "react";-import supabase from "../../utils/supabase";+import { useEffect, useState } from 'react'+import supabase from '../../utils/supabase'// realtime subscriptions need to be set up client-side// this component takes initial posts as props and automatically// updates when new posts are inserted into Supabase's `posts` tableexport default function RealtimePosts({ serverPosts }: { serverPosts: any }) {- const [posts, setPosts] = useState(serverPosts);+ const [posts, setPosts] = useState(serverPosts)useEffect(() => {// this overwrites `posts` any time the `serverPosts` prop changes// this happens when the parent Server Component is re-rendered- setPosts(serverPosts);- }, [serverPosts]);+ setPosts(serverPosts)+ }, [serverPosts])useEffect(() => {// ensure you have enabled replication on the `posts` table// https://app.supabase.com/project/_/database/replicationconst channel = supabase- .channel("*")- .on(- "postgres_changes",- { event: "INSERT", schema: "public", table: "posts" },- (payload) => setPosts((posts: any) => [...posts, payload.new])+ .channel('*')+ .on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'posts' }, (payload) =>+ setPosts((posts: any) => [...posts, payload.new]))- .subscribe();+ .subscribe()return () => {- supabase.removeChannel(channel);- };- }, [serverPosts]);+ supabase.removeChannel(channel)+ }+ }, [serverPosts])- return <pre>{JSON.stringify(posts, null, 2)}</pre>;+ return <pre>{JSON.stringify(posts, null, 2)}</pre>}diff --git a/examples/caching/with-nextjs-13-server-components/app/server-rendered/[id]/page.tsx b/examples/caching/with-nextjs-13-server-components/app/server-rendered/[id]/page.tsxindex a90b829c607..1b323e4d0c5 100644--- a/examples/caching/with-nextjs-13-server-components/app/server-rendered/[id]/page.tsx+++ b/examples/caching/with-nextjs-13-server-components/app/server-rendered/[id]/page.tsx@@ -1,31 +1,23 @@-import supabase from "../../../utils/supabase";-import { notFound } from "next/navigation";+import supabase from '../../../utils/supabase'+import { notFound } from 'next/navigation'// do not cache this page-export const revalidate = 0;+export const revalidate = 0export async function generateStaticParams() {- const { data: posts } = await supabase.from("posts").select("id");+ const { data: posts } = await supabase.from('posts').select('id')return posts?.map(({ id }) => ({id,- }));+ }))}-export default async function Post({- params: { id },-}: {- params: { id: string };-}) {- const { data: post } = await supabase- .from("posts")- .select()- .match({ id })- .single();+export default async function Post({ params: { id } }: { params: { id: string } }) {+ const { data: post } = await supabase.from('posts').select().match({ id }).single()if (!post) {- notFound();+ notFound()}- return <pre>{JSON.stringify(post, null, 2)}</pre>;+ return <pre>{JSON.stringify(post, null, 2)}</pre>}diff --git a/examples/caching/with-nextjs-13-server-components/app/server-rendered/page.tsx b/examples/caching/with-nextjs-13-server-components/app/server-rendered/page.tsxindex d18e69de208..2b96263ba99 100644--- a/examples/caching/with-nextjs-13-server-components/app/server-rendered/page.tsx+++ b/examples/caching/with-nextjs-13-server-components/app/server-rendered/page.tsx@@ -1,19 +1,19 @@-import Link from "next/link";-import supabase from "../../utils/supabase";+import Link from 'next/link'+import supabase from '../../utils/supabase'// do not cache this page-export const revalidate = 0;+export const revalidate = 0export default async function Posts() {- const { data: posts } = await supabase.from("posts").select("id, title");+ const { data: posts } = await supabase.from('posts').select('id, title')if (!posts) {- return <p>No posts found.</p>;+ return <p>No posts found.</p>}return posts.map((post) => (<p key={post.id}><Link href={`/static/${post.id}`}>{post.title}</Link></p>- ));+ ))}diff --git a/examples/caching/with-nextjs-13-server-components/app/static-with-revalidation/[id]/page.tsx b/examples/caching/with-nextjs-13-server-components/app/static-with-revalidation/[id]/page.tsxindex 15865e43ad7..06541e7a702 100644--- a/examples/caching/with-nextjs-13-server-components/app/static-with-revalidation/[id]/page.tsx+++ b/examples/caching/with-nextjs-13-server-components/app/static-with-revalidation/[id]/page.tsx@@ -1,31 +1,23 @@-import supabase from "../../../utils/supabase";-import { notFound } from "next/navigation";+import supabase from '../../../utils/supabase'+import { notFound } from 'next/navigation'// cache this page for 1 minute-export const revalidate = 60;+export const revalidate = 60export async function generateStaticParams() {- const { data: posts } = await supabase.from("posts").select("id");+ const { data: posts } = await supabase.from('posts').select('id')return posts?.map(({ id }) => ({id,- }));+ }))}-export default async function Post({- params: { id },-}: {- params: { id: string };-}) {- const { data: post } = await supabase- .from("posts")- .select()- .match({ id })- .single();+export default async function Post({ params: { id } }: { params: { id: string } }) {+ const { data: post } = await supabase.from('posts').select().match({ id }).single()if (!post) {- notFound();+ notFound()}- return <pre>{JSON.stringify(post, null, 2)}</pre>;+ return <pre>{JSON.stringify(post, null, 2)}</pre>}diff --git a/examples/caching/with-nextjs-13-server-components/app/static-with-revalidation/page.tsx b/examples/caching/with-nextjs-13-server-components/app/static-with-revalidation/page.tsxindex 224f40b4e3a..cb6879d2e28 100644--- a/examples/caching/with-nextjs-13-server-components/app/static-with-revalidation/page.tsx+++ b/examples/caching/with-nextjs-13-server-components/app/static-with-revalidation/page.tsx@@ -1,19 +1,19 @@-import Link from "next/link";-import supabase from "../../utils/supabase";+import Link from 'next/link'+import supabase from '../../utils/supabase'// cache this page for 1 minute-export const revalidate = 60;+export const revalidate = 60export default async function Posts() {- const { data: posts } = await supabase.from("posts").select("id, title");+ const { data: posts } = await supabase.from('posts').select('id, title')if (!posts) {- return <p>No posts found.</p>;+ return <p>No posts found.</p>}return posts.map((post) => (<p key={post.id}><Link href={`/static/${post.id}`}>{post.title}</Link></p>- ));+ ))}diff --git a/examples/caching/with-nextjs-13-server-components/app/static/[id]/page.tsx b/examples/caching/with-nextjs-13-server-components/app/static/[id]/page.tsxindex 817e47158f1..43f87fa9815 100644--- a/examples/caching/with-nextjs-13-server-components/app/static/[id]/page.tsx+++ b/examples/caching/with-nextjs-13-server-components/app/static/[id]/page.tsx@@ -1,28 +1,20 @@-import supabase from "../../../utils/supabase";-import { notFound } from "next/navigation";+import supabase from '../../../utils/supabase'+import { notFound } from 'next/navigation'export async function generateStaticParams() {- const { data: posts } = await supabase.from("posts").select("id");+ const { data: posts } = await supabase.from('posts').select('id')return posts?.map(({ id }) => ({id,- }));+ }))}-export default async function Post({- params: { id },-}: {- params: { id: string };-}) {- const { data: post } = await supabase- .from("posts")- .select()- .match({ id })- .single();+export default async function Post({ params: { id } }: { params: { id: string } }) {+ const { data: post } = await supabase.from('posts').select().match({ id }).single()if (!post) {- notFound();+ notFound()}- return <pre>{JSON.stringify(post, null, 2)}</pre>;+ return <pre>{JSON.stringify(post, null, 2)}</pre>}diff --git a/examples/caching/with-nextjs-13-server-components/app/static/page.tsx b/examples/caching/with-nextjs-13-server-components/app/static/page.tsxindex a9c9db32350..0465d62bbca 100644--- a/examples/caching/with-nextjs-13-server-components/app/static/page.tsx+++ b/examples/caching/with-nextjs-13-server-components/app/static/page.tsx@@ -1,16 +1,16 @@-import Link from "next/link";-import supabase from "../../utils/supabase";+import Link from 'next/link'+import supabase from '../../utils/supabase'export default async function Posts() {- const { data: posts } = await supabase.from("posts").select("id, title");+ const { data: posts } = await supabase.from('posts').select('id, title')if (!posts) {- return <p>No posts found.</p>;+ return <p>No posts found.</p>}return posts.map((post) => (<p key={post.id}><Link href={`/static/${post.id}`}>{post.title}</Link></p>- ));+ ))}diff --git a/examples/caching/with-nextjs-13-server-components/pages/api/hello.ts b/examples/caching/with-nextjs-13-server-components/pages/api/hello.tsindex f8bcc7e5cae..9bafa6e258d 100644--- a/examples/caching/with-nextjs-13-server-components/pages/api/hello.ts+++ b/examples/caching/with-nextjs-13-server-components/pages/api/hello.ts@@ -5,9 +5,6 @@ type Data = {name: string}-export default function handler(- req: NextApiRequest,- res: NextApiResponse<Data>-) {+export default function handler(req: NextApiRequest, res: NextApiResponse<Data>) {res.status(200).json({ name: 'John Doe' })}diff --git a/examples/caching/with-nextjs-13-server-components/utils/supabase.ts b/examples/caching/with-nextjs-13-server-components/utils/supabase.tsindex 555d38bd331..03729d0b486 100644--- a/examples/caching/with-nextjs-13-server-components/utils/supabase.ts+++ b/examples/caching/with-nextjs-13-server-components/utils/supabase.ts@@ -1,6 +1,6 @@-import { createClient } from "@supabase/supabase-js";+import { createClient } from '@supabase/supabase-js'export default createClient(process.env.NEXT_PUBLIC_SUPABASE_URL!,process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!-);+)