Skip to content

Commit 3de2f34

Browse files
committed
useWaitToken hook
1 parent 73513b9 commit 3de2f34

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

docs/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@
129129
"realtime/react-hooks/triggering",
130130
"realtime/react-hooks/subscribe",
131131
"realtime/react-hooks/streams",
132-
"realtime/react-hooks/swr"
132+
"realtime/react-hooks/swr",
133+
"realtime/react-hooks/use-wait-token"
133134
]
134135
},
135136
{
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: useWaitToken
3+
description: Fetch and cache data using SWR-based hooks
4+
---
5+
6+
We've added a new `useWaitToken` react hook that allows you to complete a wait token from a React component, using a Public Access Token.
7+
8+
```ts backend.ts
9+
import { wait } from "@trigger.dev/sdk";
10+
11+
// Somewhere in your code, you'll need to create the token and then pass the token ID and the public token to the frontend
12+
const token = await wait.createToken({
13+
timeout: "10m",
14+
});
15+
16+
return {
17+
tokenId: token.id,
18+
publicToken: token.publicAccessToken, // An automatically generated public access token that expires in 1 hour
19+
};
20+
```
21+
22+
Now you can use the `useWaitToken` hook in your frontend code:
23+
24+
```tsx frontend.tsx
25+
import { useWaitToken } from "@trigger.dev/react-hooks";
26+
27+
export function MyComponent({ publicToken, tokenId }: { publicToken: string; tokenId: string }) {
28+
const { complete } = useWaitToken(tokenId, {
29+
accessToken: publicToken,
30+
});
31+
32+
return <button onClick={() => complete({ foo: "bar" })}>Complete</button>;
33+
}
34+
```

0 commit comments

Comments
 (0)