Skip to main content
These hooks allow you to subscribe to runs, batches, and streams using Trigger.dev Realtime. They automatically include real-time updates for run status, metadata, output, and other properties.

Hooks

Triggering + Realtime hooks

For triggering tasks and immediately subscribing to their runs, we provide combo hooks, details on how to use them can be found in the triggering section.

Other Realtime subscription 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).