2023-10-04 10:46:00 +02:00
|
|
|
import { useState } from 'react';
|
2023-09-29 14:29:22 +02:00
|
|
|
import { useApi } from 'components/hooks/useApi';
|
2023-10-16 00:52:34 +02:00
|
|
|
import { UseQueryOptions } from '@tanstack/react-query';
|
2023-09-29 14:29:22 +02:00
|
|
|
|
2023-10-16 00:52:34 +02:00
|
|
|
export function useFilterQuery(key: any[], fn, options?: UseQueryOptions) {
|
2023-09-29 14:29:22 +02:00
|
|
|
const [params, setParams] = useState({
|
|
|
|
query: '',
|
|
|
|
page: 1,
|
|
|
|
});
|
|
|
|
const { useQuery } = useApi();
|
|
|
|
|
2023-10-04 10:46:00 +02:00
|
|
|
const { data, ...other } = useQuery([...key, params], fn.bind(null, params), options);
|
2023-09-29 14:29:22 +02:00
|
|
|
|
2023-10-04 10:46:00 +02:00
|
|
|
return {
|
|
|
|
result: data as {
|
|
|
|
page: number;
|
|
|
|
pageSize: number;
|
|
|
|
count: number;
|
|
|
|
data: any[];
|
|
|
|
},
|
|
|
|
...other,
|
|
|
|
params,
|
|
|
|
setParams,
|
|
|
|
};
|
2023-09-29 14:29:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default useFilterQuery;
|