Skip to main content
Subscribe to a run and your component re-renders whenever its status, metadata, or tags change. Build progress bars, deployment monitors, or any UI that needs to reflect what a background task is doing right now. For streaming continuous data (AI tokens, file chunks), see Streaming instead.

Trigger + subscribe combo hooks

Trigger a task and immediately subscribe to its run. Details in the triggering section.

Subscribe hooks

useRealtimeRun

The useRealtimeRun hook allows you to subscribe to a run by its ID.
To correctly type the run’s payload and output, you can provide the type of your task to the useRealtimeRun hook:
You can supply an onComplete callback to the useRealtimeRun hook to be called when the run is completed or errored. This is useful if you want to perform some action when the run is completed, like navigating to a different page or showing a notification.
When you only need run status (for example, a progress bar or completion badge), you can omit large fields like payload and output by passing skipColumns. This reduces the data sent over the wire and avoids issues such as “Large HTTP Payload” warnings in tools like Sentry.
You can skip any of: payload, output, metadata, startedAt, delayUntil, queuedAt, expiredAt, completedAt, number, isTest, usageDurationMs, costInCents, baseCostInCents, ttl, payloadType, outputType, runTags, error. The useRealtimeRunsWithTag hook also accepts a skipColumns option in the same way. See our run object reference for the complete schema and How it Works documentation for more technical details.

useRealtimeRunsWithTag

The useRealtimeRunsWithTag hook allows you to subscribe to multiple runs with a specific tag.
To correctly type the runs payload and output, you can provide the type of your task to the useRealtimeRunsWithTag hook:
If useRealtimeRunsWithTag could return multiple different types of tasks, you can pass a union of all the task types to the hook:

useRealtimeBatch

The useRealtimeBatch hook allows you to subscribe to a batch of runs by its the batch ID.
See our Realtime documentation for more information.

Using metadata to show progress in your UI

All realtime hooks automatically include metadata updates. Whenever your task updates metadata using metadata.set(), metadata.append(), or other metadata methods, your component will re-render with the updated data.
To learn how to write tasks using metadata, see our metadata guide.

Progress monitoring

This example demonstrates how to create a progress monitor component that can be used to display the progress of a run:

Reusable progress bar

This example demonstrates how to create a reusable progress bar component that can be used to display the percentage progress of a run:

Status indicator with logs

This example demonstrates how to create a status indicator component that can be used to display the status of a run, and also logs that are emitted by the task:

Multi-stage deployment monitor

This example demonstrates how to create a multi-stage deployment monitor component that can be used to display the progress of a deployment:

Type safety

Define TypeScript interfaces for your metadata to get full type safety:

Common options

accessToken & baseURL

You can pass the accessToken option to the Realtime hooks to authenticate the subscription.

enabled

You can pass the enabled option to the Realtime hooks to enable or disable the subscription.
This allows you to conditionally disable using the hook based on some state.

id

You can pass the id option to the Realtime hooks to change the ID of the subscription.
This allows you to change the ID of the subscription based on some state. Passing in a different ID will unsubscribe from the current subscription and subscribe to the new one (and remove any cached data).

Frequently asked questions

How do I show a progress bar for a background task in React?

Use metadata.set() inside your task to update a progress value, then read it with useRealtimeRun in your component. The hook re-renders your component on every metadata change. See Using metadata to show progress above for a complete example.

What’s the difference between run updates and streaming?

Run updates (this page) give you run state: status, metadata, and tags. They’re for progress bars, status badges, and dashboards. Streaming gives you continuous data like AI tokens or file chunks. Use run updates for “how far along is my task?” and streaming for “show me the output as it generates.”

Can I subscribe to multiple runs at once?

Yes. Use useRealtimeRunsWithTag to subscribe to all runs with a specific tag (e.g., user:123), or useRealtimeBatch for all runs in a batch. Each yields an array of run objects that update in real time.

Do I need to set up polling or WebSockets?

No. The hooks handle the connection automatically using Trigger.dev’s Realtime infrastructure (built on Electric SQL). Just pass a run ID and an access token.