fix: flatten queryKey to primitives for reliable TanStack Query key comparison
This commit is contained in:
parent
0ddd9b5f80
commit
6f4b46c964
@ -80,7 +80,10 @@ describe('useBrokerEvents', () => {
|
||||
it('reuses cache when query key matches', async () => {
|
||||
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
||||
|
||||
queryClient.setQueryData(['broker', 'events', 'acc-1', query], mockEventsData);
|
||||
queryClient.setQueryData(
|
||||
['broker', 'events', 'acc-1', '2026-06-22', '2026-06-29'],
|
||||
mockEventsData,
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useBrokerEvents('acc-1', query), {
|
||||
wrapper: createWrapper(queryClient),
|
||||
|
||||
@ -3,10 +3,11 @@ import type { BrokerEventsData } from '@/shared/api/responses';
|
||||
import { getBrokerEvents, type BrokerEventsQuery } from '../api/brokerEventApi';
|
||||
|
||||
export function useBrokerEvents(accountId: string | undefined, query: BrokerEventsQuery) {
|
||||
const { from, to } = query;
|
||||
return useQuery<BrokerEventsData>({
|
||||
queryKey: ['broker', 'events', accountId, query],
|
||||
queryKey: ['broker', 'events', accountId, from, to],
|
||||
enabled: Boolean(accountId),
|
||||
queryFn: async () => (await getBrokerEvents(accountId!, query)).data,
|
||||
queryFn: async () => (await getBrokerEvents(accountId!, { from, to })).data,
|
||||
staleTime: 300_000,
|
||||
retry: 2,
|
||||
refetchOnWindowFocus: false,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user