@trigger.dev/react-hooks package provides React hooks that connect your UI to the Trigger.dev Realtime API. You can trigger tasks, subscribe to run status, and receive live stream chunks — all without managing WebSocket connections or polling logic yourself.
Installation
Authentication
All hooks require a Public Access Token passed via theaccessToken option. Generate one server-side when you trigger a task (the run handle already includes one) or create a custom-scoped token with auth.createPublicToken().
Never expose your secret API key to the browser. Public Access Tokens are short-lived and
scoped to specific runs or tags. Generate them in a server route or API handler and pass them
to the client.
Hooks reference
useTaskTrigger
Trigger a task from a React component. Returns asubmit function, a loading flag, the run handle, and any submission error.
useRun
Fetch a run’s current state once (or poll withrefreshInterval). Uses SWR under the hood.
useRealtimeRun
Subscribe to live updates for a single run. Therun object is updated automatically whenever the run’s status, metadata, or tags change.
Returns:
useRealtimeRunWithStreams
Subscribe to live run updates and receive stream chunks from your task. This is the primary hook for displaying LLM output in real-time.useRealtimeTaskTrigger
CombinesuseTaskTrigger and useRealtimeRun into a single hook. Trigger a task and immediately begin watching it — no need to thread the run ID manually.
useRealtimeTaskTriggerWithStreams
Combines triggering, live run state, and stream chunks into one hook.useRealtimeRunsWithTag
Subscribe to all runs that share a tag. Useful for tracking all work associated with a user, session, or job.useRealtimeBatch
Subscribe to all runs within a batch triggered withtasks.batchTrigger().
useRealtimeStream
Subscribe to a specific named stream from a run without subscribing to the run object itself.SWR vs Realtime hooks
The package ships two styles of hooks:Prefer Realtime hooks over polling. SWR polling is limited by Trigger.dev API rate limits,
while Realtime subscriptions use efficient server-sent events.
Next steps
Realtime overview
Learn how Trigger.dev Realtime works and what you can subscribe to.
Building with AI
Patterns for LLM streaming, agent loops, and human-in-the-loop.
Wait for token
Pause a task and resume it from the browser or an external service.