/ chandeskpro / src / hooks / useCatalog.ts
swadhinbiswas Initial release v0.1.0 · 1/16/2026
ed7a4e4
17 lines · 596 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { useQuery } from '@tanstack/react-query';
import { fetchCatalog } from '../utils/apiClient';
import { useSettingsStore } from '../stores/settingsStore';

export function useCatalog(board: string, enabled: boolean = true) {
    const autoRefreshInterval = useSettingsStore((state) => state.autoRefreshInterval);

    return useQuery({
        queryKey: ['catalog', board],
        queryFn: () => fetchCatalog(board),
        staleTime: 30000, // 30 seconds
        refetchInterval: autoRefreshInterval > 0 ? autoRefreshInterval * 1000 : false,
        enabled,
        retry: 2,
    });
}