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.useRealtimeTaskTrigger
- Trigger a task and subscribe to the runuseRealtimeTaskTriggerWithStreams
- Trigger a task and subscribe to both run updates and streams
Other Realtime subscription hooks
useRealtimeRun
TheuseRealtimeRun
hook allows you to subscribe to a run by its ID.
useRealtimeRun
hook:
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.
useRealtimeRunsWithTag
TheuseRealtimeRunsWithTag
hook allows you to subscribe to multiple runs with a specific tag.
useRealtimeRunsWithTag
hook:
useRealtimeRunsWithTag
could return multiple different types of tasks, you can pass a union of all the task types to the hook:
useRealtimeBatch
TheuseRealtimeBatch
hook allows you to subscribe to a batch of runs by its the batch ID.
Using metadata to show progress in your UI
All realtime hooks automatically include metadata updates. Whenever your task updates metadata usingmetadata.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 theaccessToken
option to the Realtime hooks to authenticate the subscription.
enabled
You can pass theenabled
option to the Realtime hooks to enable or disable the subscription.
id
You can pass theid
option to the Realtime hooks to change the ID of the subscription.