All files / src/hooks useFlyerItems.ts

100% Statements 3/3
100% Branches 1/1
100% Functions 1/1
100% Lines 3/3

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                                    1x 5x   5x    
// src/hooks/useFlyerItems.ts
import type { Flyer } from '../types';
import { useFlyerItemsQuery } from './queries/useFlyerItemsQuery';
 
/**
 * A custom hook to fetch the items for a given flyer using TanStack Query (ADR-0005).
 *
 * This replaces the previous useApiOnMount implementation with TanStack Query
 * for automatic caching and better state management.
 *
 * @param selectedFlyer The flyer for which to fetch items.
 * @returns An object containing the flyer items, loading state, and any errors.
 *
 * @example
 * ```tsx
 * const { flyerItems, isLoading, error } = useFlyerItems(selectedFlyer);
 * ```
 */
export const useFlyerItems = (selectedFlyer: Flyer | null) => {
  const { data: flyerItems = [], isLoading, error } = useFlyerItemsQuery(selectedFlyer?.flyer_id);
 
  return { flyerItems, isLoading, error };
};