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.

ProductsGrid.jsx 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { Button, Container, Grid } from '@mui/material';
  2. import { Box } from '@mui/system';
  3. import Image from 'next/image';
  4. import ProductCard from '../product-card/ProductCard';
  5. const ProductsGrid = ({ allProducts, hasNextPage, fetchNextPage }) => {
  6. // const allItems = useMemo(
  7. // () => allProducts?.pages?.flatMap((page) => page.product),
  8. // [allProducts]
  9. // );
  10. const dataToDisplay = allProducts.pages.map((page) =>
  11. page.product.map((item) => (
  12. <Grid key={item._id} item md={4} sm={6} xs={12} sx={{ mb: '100px' }}>
  13. <ProductCard product={item} />
  14. </Grid>
  15. ))
  16. );
  17. // const dataToDisplay = allProducts.map((item) => (
  18. // <Grid key={item._id} item md={4} sm={6} xs={12} sx={{ mb: '100px' }}>
  19. // <ProductCard product={item} />
  20. // </Grid>
  21. // ));
  22. return (
  23. <Container
  24. sx={{
  25. mt: 10,
  26. }}
  27. >
  28. <Grid container spacing={2}>
  29. {dataToDisplay}
  30. </Grid>
  31. <Box textAlign="center" mt={-5} mb={5}>
  32. {hasNextPage && (
  33. <Button
  34. onClick={fetchNextPage}
  35. startIcon={
  36. <Image
  37. src="/images/arrow.svg"
  38. alt="arrow down"
  39. width={29}
  40. height={29}
  41. />
  42. }
  43. sx={{
  44. backgroundColor: 'primary.main',
  45. height: 50,
  46. width: 150,
  47. color: 'white',
  48. ':hover': {
  49. bgcolor: 'primary.main', // theme.palette.primary.main
  50. color: 'white',
  51. },
  52. }}
  53. >
  54. Load More
  55. </Button>
  56. )}
  57. </Box>
  58. </Container>
  59. );
  60. };
  61. export default ProductsGrid;