useApp.ts raw

   1  import useSWR, { SWRConfiguration } from "swr";
   2  
   3  import { App } from "src/types";
   4  import { swrFetcher } from "src/utils/swr";
   5  
   6  const pollConfiguration: SWRConfiguration = {
   7    refreshInterval: 3000,
   8  };
   9  
  10  export function useApp(id: number | undefined, poll = false) {
  11    return useSWR<App>(
  12      !!id && `/api/v2/apps/${id}`,
  13      swrFetcher,
  14      poll ? pollConfiguration : undefined
  15    );
  16  }
  17