diff --git a/src/frontend/hooks/server/track.ts b/src/frontend/hooks/server/track.ts index 39c8c451f..1df112c8b 100644 --- a/src/frontend/hooks/server/track.ts +++ b/src/frontend/hooks/server/track.ts @@ -2,6 +2,7 @@ import { useQueryClient, useMutation, useSuspenseQuery, + useQuery, } from '@tanstack/react-query'; import {useProject} from './projects'; import {TrackValue} from '@mapeo/schema'; @@ -33,6 +34,19 @@ export function useTracksQuery() { }); } +export function useTrackWithEnableOptionQuery(docId?: string) { + const project = useProject(); + return useQuery({ + queryKey: [TRACK_KEY], + enabled: !!docId, + queryFn: async () => { + if (!docId) return; + if (!project) throw new Error('Project instance does not exist'); + return project.track.getByDocId(docId); + }, + }); +} + export function useTrackQuery(docId: string) { const project = useProject(); return useSuspenseQuery({