File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 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 {
Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments