usePeers.ts raw

   1  import useSWR, { SWRConfiguration } from "swr";
   2  
   3  import { Peer } from "src/types";
   4  import { swrFetcher } from "src/utils/swr";
   5  
   6  const pollConfiguration: SWRConfiguration = {
   7    refreshInterval: 3000,
   8  };
   9  
  10  export function usePeers(poll = false) {
  11    return useSWR<Peer[]>(
  12      "/api/peers",
  13      swrFetcher,
  14      poll ? pollConfiguration : undefined
  15    );
  16  }
  17