Skip to main content
We provide a set of hooks that can be used to trigger tasks from your frontend application.
For triggering tasks from your frontend, you need to use “trigger” tokens. These can only be used once to trigger a task and are more secure than regular Public Access Tokens. To learn more about how to create and use these tokens, see our Trigger Tokens documentation.

Hooks

We provide three hooks for triggering tasks from your frontend application:
  • useTaskTrigger - Trigger a task from your frontend application.
  • useRealtimeTaskTrigger - Trigger a task from your frontend application and subscribe to the run.
  • useRealtimeTaskTriggerWithStreams - Trigger a task from your frontend application and subscribe to the run, and also receive any streams that are emitted by the task.

useTaskTrigger

The useTaskTrigger hook allows you to trigger a task from your frontend application.
useTaskTrigger returns an object with the following properties:
  • submit: A function that triggers the task. It takes the payload of the task as an argument.
  • handle: The run handle object. This object contains the ID of the run that was triggered, along with a Public Access Token that can be used to access the run.
  • isLoading: A boolean that indicates whether the task is currently being triggered.
  • error: An error object that contains any errors that occurred while triggering the task.
The submit function triggers the task with the specified payload. You can additionally pass an optional options argument to the submit function:

Using the handle object

You can use the handle object to initiate a subsequent Realtime hook to subscribe to the run.
We’ve also created some additional hooks that allow you to trigger tasks and subscribe to the run in one step:

useRealtimeTaskTrigger

The useRealtimeTaskTrigger hook allows you to trigger a task from your frontend application and then subscribe to the run in using Realtime:

useRealtimeTaskTriggerWithStreams

The useRealtimeTaskTriggerWithStreams hook allows you to trigger a task from your frontend application and then subscribe to the run in using Realtime, and also receive any streams that are emitted by the task.