Using the Trigger.dev v3 API from your React application.
@trigger.dev/react-hooks
package in your project:
options
that accepts an accessToken
param, which should be a valid Public Access Token. Learn more about generating tokens in the frontend guide.
TriggerAuthContext
provider
baseURL
to the TriggerAuthContext
provider.
TriggerAuthContext
is a client component. So for example, the following code will not work:
Page
is a server component and the TriggerAuthContext.Provider
uses client-only react code. To fix this, wrap the TriggerAuthContext.Provider
in a client component:
/runs/[id].tsx
page, you can read the token from the cookie and pass it to the TriggerProvider
.
/runs/[id].tsx
page:
useRealtime*
are Realtime hooks, and all hooks named use*
are SWR hooks.
useRealtimeRun
hook allows you to subscribe to a run by its ID.
useRealtimeRun
hook:
useRealtimeRunsWithTag
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
hook allows you to subscribe to a batch of runs by its the batch ID.
useRealtimeRunWithStreams
hook allows you to subscribe to a run by its ID and also receive any streams that are emitted by the task. See our Realtime documentation for more information about emitting streams from a task.
useRealtimeRunWithStreams
hook:
enabled
option to the Realtime hooks to enable or disable the subscription.
id
option to the Realtime hooks to change the ID of the subscription.
*withStreams
variants of the Realtime hooks accept an experimental_throttleInMs
option to throttle the updates from the server. This can be useful if you are getting too many updates and want to reduce the number of updates.
useRun
hook allows you to fetch a run by its ID.
run
object returned is the same as the run object returned by the Trigger.dev API. To correctly type the run’s payload and output, you can provide the type of your task to the useRun
hook:
write
permissions to use these hooks. See our frontend guide for more information.
useTaskTrigger
hook allows you to trigger a task from your frontend application.
useRealtimeTaskTrigger
hook allows you to trigger a task from your frontend application and then subscribe to the run in using Realtime:
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.