Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
feat(hooks): add react-query hook to fetch live submissions
Browse files Browse the repository at this point in the history
  ## what
  - add react-query hook to fetch live submissions
    - provide
      - pollId
      - fetchInterval

  ## how

  ## why
  - this will be used to fetch live submissions in an interval

  ## where
  - ./src/hooks/index.ts

  ## usage
  • Loading branch information
Clumsy-Coder committed Jan 16, 2024
1 parent 9f14cad commit b219274
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import axios from "axios";
import { useQuery } from "@tanstack/react-query";

import { Submission } from "@/types";

/**
* Enum for React Query Keys when using React-query
*/
export enum queryKey {
polling = "live-polling",
}

/**
* Fetch live submission (polling)
*/
export const useFetchLiveSubmission = (pollId = 0, fetchInterval = 5000) => {
return useQuery({
queryKey: [queryKey.polling],
queryFn: async () => {
const { data } = await axios.get<Submission[]>(`/api/poll/${pollId}`);

return data;
},
refetchInterval: fetchInterval,
});
};

0 comments on commit b219274

Please sign in to comment.