You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (error) return <div>Error: {error.message}</div>;
91
-
92
-
return <div>Run: {run.id}</div>;
93
-
}
94
-
```
95
-
96
-
The `run` object returned is the same as the [run object](/management/runs/retrieve) returned by the Trigger.dev API. To correctly type the run's payload and output, you can provide the type of your task to the `useRun` hook:
description: Fetch and cache data using SWR-based hooks
5
+
---
6
+
7
+
SWR hooks use the [swr](https://swr.vercel.app/) library to fetch data once and cache it. These hooks are useful when you need to fetch data without real-time updates.
8
+
9
+
<Note>
10
+
While SWR can be configured to poll for updates, we recommend using the [Realtime
11
+
hooks](/realtime/react-hooks/realtime) for most use-cases due to rate-limits and the way the
12
+
Trigger.dev API works.
13
+
</Note>
14
+
15
+
## useRun
16
+
17
+
The `useRun` hook allows you to fetch a run by its ID.
18
+
19
+
```tsx
20
+
"use client"; // This is needed for Next.js App Router or other RSC frameworks
if (error) return <div>Error: {error.message}</div>;
29
+
30
+
return <div>Run: {run.id}</div>;
31
+
}
32
+
```
33
+
34
+
The `run` object returned is the same as the [run object](/management/runs/retrieve) returned by the Trigger.dev API. To correctly type the run's payload and output, you can provide the type of your task to the `useRun` hook:
0 commit comments