diff --git a/packages/pl-hooks/lib/hooks/polls/usePoll.ts b/packages/pl-hooks/lib/hooks/polls/usePoll.ts new file mode 100644 index 0000000000..2974281a17 --- /dev/null +++ b/packages/pl-hooks/lib/hooks/polls/usePoll.ts @@ -0,0 +1,17 @@ +import { useQuery } from '@tanstack/react-query'; + +import { usePlHooksApiClient } from 'pl-hooks/contexts/api-client'; +import { usePlHooksQueryClient } from 'pl-hooks/contexts/query-client'; + +const usePoll = (pollId?: string) => { + const queryClient = usePlHooksQueryClient(); + const { client } = usePlHooksApiClient(); + + return useQuery({ + queryKey: ['polls', 'entities', pollId], + queryFn: () => client.polls.getPoll(pollId!), + enabled: !!pollId, + }, queryClient); +}; + +export { usePoll };