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 };
};
|