Files
flyer-crawler.projectium.com/src/providers/FlyersProvider.tsx
Torben Sorensen 38eb810e7a
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 11m55s
logging the frontend loop
2025-12-30 23:28:38 -08:00

35 lines
1.1 KiB
TypeScript

// src/providers/FlyersProvider.tsx
import React, { ReactNode } from 'react';
import { FlyersContext, FlyersContextType } from '../contexts/FlyersContext';
import type { Flyer } from '../types';
import * as apiClient from '../services/apiClient';
import { useInfiniteQuery } from '../hooks/useInfiniteQuery';
import { useCallback } from 'react';
export const FlyersProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
// Memoize the fetch function to ensure stability for the useInfiniteQuery hook.
const fetchFlyersFn = useCallback(apiClient.fetchFlyers, []);
const {
data: flyers,
isLoading: isLoadingFlyers,
error: flyersError,
fetchNextPage: fetchNextFlyersPage,
hasNextPage: hasNextFlyersPage,
refetch: refetchFlyers,
isRefetching: isRefetchingFlyers,
} = useInfiniteQuery<Flyer>(fetchFlyersFn);
const value: FlyersContextType = {
flyers: flyers || [],
isLoadingFlyers,
flyersError,
fetchNextFlyersPage,
hasNextFlyersPage,
isRefetchingFlyers,
refetchFlyers,
};
return <FlyersContext.Provider value={value}>{children}</FlyersContext.Provider>;
};