Using the Trigger.dev v3 API from your React application.
@trigger.dev/react-hooks
package in your project:
TriggerAuthContext
provider. Learn more about authentication in the frontend guide.
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.
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:
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.