Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

useInfiniteQuery.js 635B

123456789101112131415161718192021
  1. import { useInfiniteQuery } from '@tanstack/react-query';
  2. import { getAllProducts } from '../requests/products/productRequest';
  3. export const useInfiniteProducts = (filter) => {
  4. return useInfiniteQuery(
  5. ['products'],
  6. async ({ pageParam = 1 }) => await getAllProducts(pageParam),
  7. {
  8. getNextPageParam: (lastPage, pages) => {
  9. const maxPages = Math.ceil(lastPage?.productCount / 9);
  10. const nextPage = pages.length + 1;
  11. if (nextPage <= maxPages) {
  12. return nextPage;
  13. }
  14. },
  15. enabled: filter === 'All' || filter === '',
  16. staleTime: 0,
  17. cacheTime: 0,
  18. }
  19. );
  20. };