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.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 dataToDisplay = allProducts.pages.map((page) =>
  7. page.product.map((item) => (
  8. <Grid key={item._id} item md={4} sm={6} xs={12} sx={{ mb: '100px' }}>
  9. <ProductCard product={item} />
  10. </Grid>
  11. ))
  12. );
  13. return (
  14. <Container
  15. sx={{
  16. mt: 10,
  17. }}
  18. >
  19. <Grid container spacing={2}>
  20. {dataToDisplay}
  21. </Grid>
  22. <Box textAlign="center" mt={-5} mb={5}>
  23. {hasNextPage && (
  24. <Button
  25. onClick={fetchNextPage}
  26. startIcon={
  27. <Image
  28. src="/images/arrow.svg"
  29. alt="arrow down"
  30. width={29}
  31. height={29}
  32. />
  33. }
  34. sx={{
  35. backgroundColor: 'primary.main',
  36. height: 50,
  37. width: 150,
  38. color: 'white',
  39. ':hover': {
  40. bgcolor: 'primary.main', // theme.palette.primary.main
  41. color: 'white',
  42. },
  43. }}
  44. >
  45. Load More
  46. </Button>
  47. )}
  48. </Box>
  49. </Container>
  50. );
  51. };
  52. export default ProductsGrid;