pl-hooks: add usePoll
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
0d2347117f
commit
d76a7e974b
1 changed files with 17 additions and 0 deletions
17
packages/pl-hooks/lib/hooks/polls/usePoll.ts
Normal file
17
packages/pl-hooks/lib/hooks/polls/usePoll.ts
Normal file
|
@ -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 };
|
Loading…
Reference in a new issue