references/realtime-hooks-test/README.md
This is a comprehensive testing reference project for the @trigger.dev/react-hooks package. It demonstrates all the realtime hooks available in useRealtime.ts.
This project includes examples for:
useRealtimeRun - Subscribe to a single task runuseRealtimeRunWithStreams - Subscribe to a run with stream datauseRealtimeRunsWithTag - Subscribe to multiple runs by taguseRealtimeBatch - Subscribe to a batch of runsuseRealtimeStream - Subscribe to a specific streamFrom the repository root:
pnpm install
Create a .env.local file:
TRIGGER_SECRET_KEY=your_secret_key
TRIGGER_PROJECT_REF=your_project_ref
NEXT_PUBLIC_TRIGGER_PUBLIC_KEY=your_public_key
NEXT_PUBLIC_TRIGGER_API_URL=http://localhost:3030
In one terminal, run the Trigger.dev dev server:
pnpm run dev:trigger
In another terminal, run the Next.js dev server:
pnpm run dev
Visit http://localhost:3000 to see the examples.
src/
├── app/
│ ├── page.tsx # Home page with navigation
│ ├── actions.ts # Server actions for triggering tasks
│ ├── run/[id]/page.tsx # useRealtimeRun example
│ ├── run-with-streams/[id]/page.tsx # useRealtimeRunWithStreams example
│ ├── runs-with-tag/[tag]/page.tsx # useRealtimeRunsWithTag example
│ ├── batch/[id]/page.tsx # useRealtimeBatch example
│ └── stream/[id]/page.tsx # useRealtimeStream example
├── components/
│ ├── run-viewer.tsx # Component using useRealtimeRun
│ ├── run-with-streams-viewer.tsx # Component using useRealtimeRunWithStreams
│ ├── runs-with-tag-viewer.tsx # Component using useRealtimeRunsWithTag
│ ├── batch-viewer.tsx # Component using useRealtimeBatch
│ └── stream-viewer.tsx # Component using useRealtimeStream
└── trigger/
├── simple-task.ts # Simple task for useRealtimeRun
├── stream-task.ts # Task with streams for useRealtimeRunWithStreams
├── tagged-task.ts # Tasks that use tags
└── batch-task.ts # Tasks for batch operations
Each page demonstrates different aspects of the hooks:
/run/[id])/run-with-streams/[id])/runs-with-tag/[tag])/batch/[id])/stream/[id])