new-project/app/page.tsx

32 lines
No EOL
1 KiB
TypeScript

import { useEffect, useState } from 'react';
import { createClient } from '@supabase/supabase-js';
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL || 'https://your-supabase-url';
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || 'your-anon-key';
const supabase = createClient(supabaseUrl, supabaseAnonKey);
export default function Home() {
const [count, setCount] = useState(0);
useEffect(() => {
const fetchCount = async () => {
const { count: fetchedCount } = await supabase.from('example_table').select('count').single();
setCount(fetchedCount);
};
fetchCount();
}, []);
return (
<main className="flex min-h-screen flex-col items-center justify-center p-4">
<h1 className="text-3xl font-bold mb-4">Freight PWA</h1>
<p className="mb-2">Current count from DB: {count}</p>
<button
onClick={() => setCount((c) => c + 1)}
className="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600"
>
Increment
</button>
</main>
);
}