You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

useInfiniteQuery.js 666B

123456789101112131415161718192021222324
  1. import { useInfiniteQuery } from '@tanstack/react-query';
  2. import { getAllProducts } from '../requests/products/productRequest';
  3. export const useInfiniteProducts = (category, filter) => {
  4. return useInfiniteQuery(
  5. ['products', category, filter],
  6. async ({ pageParam = 1 }) =>
  7. await getAllProducts(
  8. pageParam,
  9. category === '' ? 'All' : category,
  10. filter === '' ? 'asc' : filter
  11. ),
  12. {
  13. getNextPageParam: (lastPage, pages) => {
  14. if (lastPage.next !== null) {
  15. return pages.length + 1;
  16. }
  17. },
  18. refetchOnWindowFocus: false,
  19. staleTime: 60000,
  20. cacheTime: 300000,
  21. }
  22. );
  23. };