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.

1

Install the package

Add the @trigger.dev/react package to your project:

npm install @trigger.dev/react@latest
2

Get your public API key

In the Trigger.dev dashboard you should go to your Project and then the “Environments & API Keys” page.

Get your public API Key

You should copy the PUBLIC API key for the dev environment.

3

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.

.env.local
#...
TRIGGER_API_KEY=[your_private_api_key]
NEXT_PUBLIC_TRIGGER_PUBLIC_API_KEY=[your_public_api_key]
#...

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.

4

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.

app/layout.tsx
export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body className={inter.className}>
        <TriggerProvider publicApiKey={process.env.NEXT_PUBLIC_TRIGGER_PUBLIC_API_KEY!}>
          {children}
        </TriggerProvider>
      </body>
    </html>
  );
}

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.