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:
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: