File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -12,4 +12,5 @@ export * from './devices/use-device-providers.js'
1212export * from './devices/use-devices.js'
1313export * from './SeamProvider.js'
1414export * from './use-seam-client.js'
15+ export * from './use-seam-query.js'
1516export * from './use-seam-query-result.js'
Original file line number Diff line number Diff line change 1+ import type { SeamHttpApiError , SeamHttpEndpoints } from '@seamapi/http/connect'
2+ import { useQuery , type UseQueryResult } from '@tanstack/react-query'
3+
4+ import { useSeamClient } from 'lib/seam/use-seam-client.js'
5+
6+ type EndpointsOnly = Pick <
7+ SeamHttpEndpoints ,
8+ '/devices/list' | '/devices/get' | '/action_attempts/get'
9+ >
10+
11+ export function useSeamQuery < T extends keyof EndpointsOnly > (
12+ endpointPath : T ,
13+ params ?: Parameters < EndpointsOnly [ T ] > [ 0 ] ,
14+ options ?: Parameters < EndpointsOnly [ T ] > [ 1 ]
15+ ) : UseQueryResult < Awaited < ReturnType < EndpointsOnly [ T ] > > , SeamHttpApiError > {
16+ const { endpointClient : client } = useSeamClient ( )
17+ return useQuery ( {
18+ enabled : client != null ,
19+ queryKey : [ endpointPath , params ] ,
20+ queryFn : async ( ) => {
21+ if ( client == null ) return null
22+ const endpoint = client [ endpointPath ] as EndpointsOnly [ T ]
23+ // @ts -expect-error: The types are correct at runtime, but TypeScript can't infer the specific endpoint types
24+ return await endpoint ( params , options )
25+ } ,
26+ } )
27+ }
You can’t perform that action at this time.
0 commit comments