diff --git a/.changeset/honest-trains-burn.md b/.changeset/honest-trains-burn.md new file mode 100644 index 0000000000..15cc2742d9 --- /dev/null +++ b/.changeset/honest-trains-burn.md @@ -0,0 +1,5 @@ +--- +"@trigger.dev/react-hooks": patch +--- + +useBatch renamed to useRealtimeBatch diff --git a/packages/react-hooks/src/hooks/useRealtimeBatch.ts b/packages/react-hooks/src/hooks/useRealtimeBatch.ts index 678c65a1bc..e50ab8bce7 100644 --- a/packages/react-hooks/src/hooks/useRealtimeBatch.ts +++ b/packages/react-hooks/src/hooks/useRealtimeBatch.ts @@ -4,7 +4,21 @@ import { AnyTask, InferRunTypes, TaskRunShape } from "@trigger.dev/core/v3"; import { useEffect, useState } from "react"; import { useApiClient } from "./useApiClient.js"; -export function useBatch(batchId: string) { +/** + * hook to subscribe to realtime updates of a batch of task runs. + * + * @template TTask - The type of the task. + * @param {string} batchId - The unique identifier of the batch to subscribe to. + * @returns {{ runs: TaskRunShape[], error: Error | null }} An object containing the current state of the runs and any error encountered. + * + * @example + * + * ```ts + * import type { myTask } from './path/to/task'; + * const { runs, error } = useRealtimeBatch('batch-id-123'); + * ``` + */ +export function useRealtimeBatch(batchId: string) { const [runShapes, setRunShapes] = useState[]>([]); const [error, setError] = useState(null); const apiClient = useApiClient(); diff --git a/references/nextjs-realtime/src/app/batches/[id]/ClientBatchRunDetails.tsx b/references/nextjs-realtime/src/app/batches/[id]/ClientBatchRunDetails.tsx index 6f4fc4d1d1..1f0b63f8c9 100644 --- a/references/nextjs-realtime/src/app/batches/[id]/ClientBatchRunDetails.tsx +++ b/references/nextjs-realtime/src/app/batches/[id]/ClientBatchRunDetails.tsx @@ -1,7 +1,7 @@ "use client"; import { Card, CardContent } from "@/components/ui/card"; -import { TriggerAuthContext, useBatch } from "@trigger.dev/react-hooks"; +import { TriggerAuthContext, useRealtimeBatch } from "@trigger.dev/react-hooks"; import type { exampleTask } from "@/trigger/example"; import { Badge } from "@/components/ui/badge"; @@ -117,7 +117,7 @@ export function BackgroundRunsTable({ runs }: { runs: TaskRunShape(batchId); + const { runs, error } = useRealtimeBatch(batchId); console.log(runs);