Skip to content

Commit ce1a54e

Browse files
authored
Renamed useBatch to useRealtimeBatch (#1447)
* Renamed useBatch to useRealtimeBatch * Use the new hook name in the nextjs-realtime ref
1 parent 2528548 commit ce1a54e

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

.changeset/honest-trains-burn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/react-hooks": patch
3+
---
4+
5+
useBatch renamed to useRealtimeBatch

packages/react-hooks/src/hooks/useRealtimeBatch.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@ import { AnyTask, InferRunTypes, TaskRunShape } from "@trigger.dev/core/v3";
44
import { useEffect, useState } from "react";
55
import { useApiClient } from "./useApiClient.js";
66

7-
export function useBatch<TTask extends AnyTask>(batchId: string) {
7+
/**
8+
* hook to subscribe to realtime updates of a batch of task runs.
9+
*
10+
* @template TTask - The type of the task.
11+
* @param {string} batchId - The unique identifier of the batch to subscribe to.
12+
* @returns {{ runs: TaskRunShape<TTask>[], error: Error | null }} An object containing the current state of the runs and any error encountered.
13+
*
14+
* @example
15+
*
16+
* ```ts
17+
* import type { myTask } from './path/to/task';
18+
* const { runs, error } = useRealtimeBatch<typeof myTask>('batch-id-123');
19+
* ```
20+
*/
21+
export function useRealtimeBatch<TTask extends AnyTask>(batchId: string) {
822
const [runShapes, setRunShapes] = useState<TaskRunShape<TTask>[]>([]);
923
const [error, setError] = useState<Error | null>(null);
1024
const apiClient = useApiClient();

references/nextjs-realtime/src/app/batches/[id]/ClientBatchRunDetails.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import { Card, CardContent } from "@/components/ui/card";
4-
import { TriggerAuthContext, useBatch } from "@trigger.dev/react-hooks";
4+
import { TriggerAuthContext, useRealtimeBatch } from "@trigger.dev/react-hooks";
55
import type { exampleTask } from "@/trigger/example";
66

77
import { Badge } from "@/components/ui/badge";
@@ -117,7 +117,7 @@ export function BackgroundRunsTable({ runs }: { runs: TaskRunShape<typeof exampl
117117
}
118118

119119
function BatchRunTableWrapper({ batchId }: { batchId: string }) {
120-
const { runs, error } = useBatch<typeof exampleTask>(batchId);
120+
const { runs, error } = useRealtimeBatch<typeof exampleTask>(batchId);
121121

122122
console.log(runs);
123123

0 commit comments

Comments
 (0)