mirror of
https://github.com/thatmattlove/hyperglass.git
synced 2026-04-21 15:28:30 +00:00
19 lines
540 B
TypeScript
19 lines
540 B
TypeScript
import { useQuery } from 'react-query';
|
|
|
|
import type { TASNDetails } from '~/types';
|
|
import type { TUseASNDetailFn } from './types';
|
|
|
|
async function query(ctx: TUseASNDetailFn): Promise<TASNDetails> {
|
|
const [asn] = ctx.queryKey;
|
|
const res = await fetch(`https://api.bgpview.io/asn/${asn}`, { mode: 'cors' });
|
|
return await res.json();
|
|
}
|
|
|
|
export function useASNDetail(asn: string) {
|
|
return useQuery(asn, query, {
|
|
refetchOnWindowFocus: false,
|
|
refetchInterval: false,
|
|
refetchOnMount: false,
|
|
cacheTime: Infinity,
|
|
});
|
|
}
|