React hooks: Overview
How to show the live status of Job Runs in your React app
You can display the live progress of a Job Run to your users, including the status of individual tasks and the final output of the Run.
This updates live as the Job progresses, until we show the "Posted to Slack" output
Setting up your project for hooks
This guide assumes that your project is already setup and you have a Job running. If not, you should follow the quick start guide first.
Install the package
Add the @trigger.dev/react
package to your project:
Get your public API key
In the Trigger.dev dashboard you should go to your Project and then the “Environments & API Keys” page.
You should copy the PUBLIC
API key for the dev environment.
Setting up environment variables
Add the NEXT_PUBLIC_TRIGGER_PUBLIC_API_KEY
environment variable to your project. This will be used by the TriggerProvider
component to connect to the Trigger API.
Your private API key should already be in there.
NEXT_PUBLIC_
is a special prefix that exposes the environment variable to your users’ web browsers.
Add the <TriggerProvider> component
The TriggerProvider component is a React Context Provider that will make the Trigger API client available to all child components.
Generally you’ll want to add this to the root of your app, so that it’s available everywhere. However, you can add it lower in the hierarchy but it must be above any of the hooks.
Two ways to report Run progress
Automatic progress – without writing additional code in your Job you can get updates on the overall run status and individual tasks inside the run.
Explicit status – add code to your Job that reports the status of the things you’re doing. This gives you full flexibility for displaying progress in your UI.
Was this page helpful?