1
1
---
2
2
description: Guidelines for writing Trigger.dev tasks
3
- globs: **/trigger/**/*.ts, **/trigger/**/*.tsx
3
+ globs: **/trigger/**/*.ts, **/trigger/**/*.tsx,**/trigger/**/*.js,**/trigger/**/*.jsx
4
4
alwaysApply: false
5
5
---
6
6
# How to write Trigger.dev tasks
@@ -832,7 +832,7 @@ npm add @trigger.dev/react-hooks
832
832
833
833
All hooks require a Public Access Token. You can provide it directly to each hook:
834
834
835
- ```typescriptx
835
+ ```typescript
836
836
import { useRealtimeRun } from "@trigger.dev/react-hooks";
837
837
838
838
function MyComponent({ runId, publicAccessToken }) {
@@ -845,7 +845,7 @@ function MyComponent({ runId, publicAccessToken }) {
845
845
846
846
Or use the `TriggerAuthContext` provider:
847
847
848
- ```typescriptx
848
+ ```typescript
849
849
import { TriggerAuthContext } from "@trigger.dev/react-hooks";
850
850
851
851
function SetupTrigger({ publicAccessToken }) {
@@ -859,7 +859,7 @@ function SetupTrigger({ publicAccessToken }) {
859
859
860
860
For Next.js App Router, wrap the provider in a client component:
861
861
862
- ```typescriptx
862
+ ```typescript
863
863
// components/TriggerProvider.tsx
864
864
"use client";
865
865
@@ -879,7 +879,7 @@ export function TriggerProvider({ accessToken, children }) {
879
879
Several approaches for Next.js App Router:
880
880
881
881
1. **Using cookies**:
882
- ```typescriptx
882
+ ```typescript
883
883
// Server action
884
884
export async function startRun() {
885
885
const handle = await tasks.trigger<typeof exampleTask>("example", { foo: "bar" });
@@ -899,7 +899,7 @@ export default function RunPage({ params }) {
899
899
```
900
900
901
901
2. **Using query parameters**:
902
- ```typescriptx
902
+ ```typescript
903
903
// Server action
904
904
export async function startRun() {
905
905
const handle = await tasks.trigger<typeof exampleTask>("example", { foo: "bar" });
@@ -908,7 +908,7 @@ export async function startRun() {
908
908
```
909
909
910
910
3. **Server-side token generation**:
911
- ```typescriptx
911
+ ```typescript
912
912
// Page component
913
913
export default async function RunPage({ params }) {
914
914
const publicAccessToken = await generatePublicAccessToken(params.id);
@@ -938,7 +938,7 @@ export async function generatePublicAccessToken(runId: string) {
938
938
939
939
Data fetching hooks that use SWR for caching:
940
940
941
- ```typescriptx
941
+ ```typescript
942
942
"use client";
943
943
import { useRun } from "@trigger.dev/react-hooks";
944
944
import type { myTask } from "@/trigger/myTask";
0 commit comments