A hook that helps you fetch a list of resources.

The hook uses useQuery from @tanstack/react-query to fetch data and cache it. It accepts various query options and performs an API request to fetch a list of resources based on the provided resource and params. The hook supports additional query parameters and custom API client parameters.

If a custom queryFn is provided, it will be used to perform the query; otherwise, the default API client method will be used. The queryKey is constructed based on the resource path and additional parameters to ensure proper caching and refetching.

import { useGetList } from 'react-query-manager';

type TData = { id: 1, name: 'Test' };
const PATH = 'users/{id}/messages';

const queryList = useGetList<typeof PATH, TData>({
resource: { path: PATH, params: { id: 1 } },
queryOptions: {
onSuccess: (data) => {
console.log('Data fetched successfully:', data);
},
},
params: { sortBy: 'price', order: 'asc' },
});