Some checks failed
Deploy to Test Environment / deploy-to-test (push) Failing after 3h0m5s
Tests were accessing response.body directly instead of response.body.data,
causing failures since sendSuccess() wraps responses in { success, data }.
24 lines
828 B
TypeScript
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 };
|
|
};
|