-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuseGetCallbyId.ts
29 lines (24 loc) · 958 Bytes
/
useGetCallbyId.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* eslint-disable @typescript-eslint/no-unused-vars */
import { Call, useStreamVideoClient } from "@stream-io/video-react-sdk"
import { useEffect, useState } from "react";
// this id is basically is coming from clerk
export const useGetCallbyId = (id: string | string[]) => {
const [call, setCall] = useState<Call>();
const [isCallLoading, setIsCallLoading] = useState(true)
const client = useStreamVideoClient();
useEffect(() => {
if(!client) return;
const loadcall = async () => {
try {
const { calls } = await client.queryCalls({ filter_conditions: { id }})
if(calls.length > 0) setCall(calls[0])
setIsCallLoading(false)
} catch (error) {
console.log("Error in GetCallbyHooks", error)
setIsCallLoading(false)
}
}
loadcall()
},[id, client])
return { call, isCallLoading}
}