Files
flyer-crawler.projectium.com/src/hooks/useFlyerItems.ts
Torben Sorensen 2f1d73ca12
Some checks failed
Deploy to Test Environment / deploy-to-test (push) Failing after 3h0m5s
fix(tests): access wrapped API response data correctly
Tests were accessing response.body directly instead of response.body.data,
causing failures since sendSuccess() wraps responses in { success, data }.
2026-01-09 23:16:30 -08:00

24 lines
828 B
TypeScript

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