Open History to see the last commit
1import { and, eq, gte, lte, useLiveQuery } from '@tanstack/react-db'
2import settlementsCollection from './settlementsCollection'
3import type { SettlementsSearch } from './types'
4
5function useSettlementsQuery(search: SettlementsSearch) {
6 return useLiveQuery(
7 (query) =>
8 query
9 .from({ settlement: settlementsCollection })
10 .where(({ settlement }) =>
11 and(
12 eq(settlement.currency, search.currency ?? settlement.currency),
13 gte(settlement.from, search.from ?? settlement.from),
14 lte(settlement.to, search.to ?? settlement.to),
15 ),
16 ),
17 [search.currency, search.from, search.to],
18 )
19}
20
21export default useSettlementsQuery