Skip to content

Commit 816b0f9

Browse files
committed
Add some more react hooks & realtime docs
1 parent 6fb0736 commit 816b0f9

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

docs/mint.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@
214214
"pages": [
215215
"realtime/overview",
216216
"realtime/subscribe-to-run",
217-
"realtime/subscribe-to-runs-with-tag"
217+
"realtime/subscribe-to-runs-with-tag",
218+
"realtime/use-realtime-run",
219+
"realtime/use-realtime-runs-with-tag"
218220
]
219221
},
220222
{

docs/realtime/overview.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ for await (const run of runs.subscribeToBatch("batch-id")) {
6969
}
7070
```
7171

72+
### React hooks
73+
74+
We also provide a set of React hooks that make it easy to use the Realtime API in your React components. See the [React hooks doc](/frontend/react-hooks) for more information.
75+
7276
## Run changes
7377

7478
You will receive updates whenever a run changes for the following reasons:

docs/realtime/use-realtime-run.mdx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: useRealtimeRun
3+
sidebarTitle: useRealtimeRun
4+
description: Subscribes to all changes to a run in a React component.
5+
---
6+
7+
import RunObject from "/snippets/realtime/run-object.mdx";
8+
9+
<RequestExample>
10+
11+
```ts Example
12+
import { useRealtimeRun } from "@trigger.dev/react-hooks";
13+
import type { myTask } from "./trigger/tasks";
14+
15+
export function MyComponent({ runId }: { runId: string }) {
16+
const { run, error } = useRealtimeRun<typeof myTask>(runId);
17+
18+
if (error) return <div>Error: {error.message}</div>;
19+
20+
return <div>Run: {run.id}</div>;
21+
}
22+
```
23+
24+
</RequestExample>
25+
26+
This react hook subscribes to all changes to a run. See the [React hooks doc](/frontend/react-hooks) for more information on how to use this hook.
27+
28+
### Response
29+
30+
The react hook returns an object with the following properties:
31+
32+
<ParamField path="run" type="object" required>
33+
The run object. See the [Run object doc](realtime/overview#run-object) for more information.
34+
</ParamField>
35+
36+
<ParamField path="error" type="Error">
37+
An error object if an error occurred while subscribing to a run.
38+
</ParamField>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: useRealtimeRunsWithTag
3+
sidebarTitle: useRealtimeRunsWithTag
4+
description: Subscribes to all changes to runs with a specific tag in a React component.
5+
---
6+
7+
import RunObject from "/snippets/realtime/run-object.mdx";
8+
9+
<RequestExample>
10+
11+
```ts Example
12+
import { useRealtimeRunsWithTag } from "@trigger.dev/react-hooks";
13+
import type { myTask, myOtherTask } from "./trigger/tasks";
14+
15+
export function MyComponent({ tag }: { tag: string }) {
16+
const { runs, error } = useRealtimeRunsWithTag<typeof myTask | typeof myOtherTask>(tag);
17+
18+
if (error) return <div>Error: {error.message}</div>;
19+
20+
return (
21+
<div>
22+
{runs.map((run) => (
23+
<div key={run.id}>Run: {run.id}</div>
24+
))}
25+
</div>
26+
);
27+
}
28+
```
29+
30+
</RequestExample>
31+
32+
This react hook subscribes to all changes to runs with a specific tag. See the [React hooks doc](/frontend/react-hooks) for more information on how to use this hook.
33+
34+
### Response
35+
36+
The react hook returns an object with the following properties:
37+
38+
<ParamField path="runs" type="object[]" required>
39+
An array of run objects. See the [Run object doc](/realtime/overview#run-object) for more
40+
information.
41+
</ParamField>
42+
43+
<ParamField path="error" type="Error">
44+
An error object if an error occurred while subscribing.
45+
</ParamField>

0 commit comments

Comments
 (0)