Return

All tests / hooks useIndexedPages.ts

84.61% Statements 11/13
0% Branches 0/1
100% Functions 2/2
83.33% Lines 10/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 314x     4x   4x 1x 1x     1x       4x 6x             6x             6x  
import useSWR from 'swr';
import type { CounterData } from '../types/api';
 
const url = `${process.env.NEXT_PUBLIC_DOMAIN}/api/indexed-pages`;
 
const fetchCounter = async (url: string): Promise<CounterData> => {
    const response = await fetch(url);
    Iif (!response.ok) {
        throw new Error(`Failed to fetch counter data: ${response.statusText}`);
    }
    const data = await response.json();
    return data as CounterData;
};
 
const useIndexedPages = () => {
    const { data, error, isLoading } = useSWR<CounterData>(url, fetchCounter, {
        dedupingInterval: 5000,
        fallbackData: {
            num: 0,
        },
    });
 
    return {
        data,
        error,
        loading: isLoading,
    };
};
 
export default useIndexedPages;