Skip to main content
The @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 the accessToken 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 a submit function, a loading flag, the run handle, and any submission error.
Returns:

useRun

Fetch a run’s current state once (or poll with refreshInterval). Uses SWR under the hood.
Returns:

useRealtimeRun

Subscribe to live updates for a single run. The run object is updated automatically whenever the run’s status, metadata, or tags change.
Options: 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.
Returns:

useRealtimeTaskTrigger

Combines useTaskTrigger 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 with tasks.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.