Quick Start
We’ll get Cuttlefish running in a Next.js app in 5 minutes.1
Prerequisites
Before we begin, we’ll need:Node.js 20+ - Required for running the Cuttlefish dev server and our Next.js app.A Next.js app - Don’t have one? Create a new Next.js app:A local Postgres database - Don’t have one? Run Postgres with Docker:A database table to query - Starting fresh? Create a sample
todos table:2
Installation
Install Cuttlefish packages:
3
Setup
We’ll wrap our app with
CuttlefishProvider in app/layout.tsx:4
Start the dev server
In a separate terminal, start the Cuttlefish dev server:We should see:
Cuttlefish Engine running on http://localhost:40005
Your first live query
The
useLiveQuery hook executes a SQL query and automatically updates our component when data changes in the database. It returns data, loading, and error states just like any async hook.Create app/page.tsx:6
Verify it works
Let’s open our Next.js app in the browser at Watch the browser - the new todo appears instantly, with no page refresh.This is Cuttlefish’s core value: our UI stays synchronized with the database in real-time. Any change to the database - whether from another user, a background job, or a manual SQL command - appears immediately in all connected clients.
http://localhost:3000. We should see “My Todos” with our existing todos (or an empty list).Now let’s see live updates in action. Open a new terminal and insert a todo directly into the database:Next steps
Congratulations! We’ve built our first live-updating React app with Cuttlefish. Learn the concepts:- Understand how Cuttlefish works - Live Partial Replica architecture, Composable Sync, and more
- Use Kysely for type-safe queries - Get full TypeScript type safety with Kysely
- Query local data only - Use
useLocalLiveQueryfor instant, zero-latency queries - Optimize with Composable Sync - Replicate once, query infinitely
- Add authentication - Integrate with your existing auth system
useLiveQuery- Live query hookuseLocalLiveQuery- Local-only queriesreplicateQuery- Manual replication control