skip to Main Content

I have a problem reoccurring in my project. I have a component ProductCard and I render in the Home component. So this is the ProductCard component

<div className={location.pathname === "/store" ? `gr-${grid}` : "col-3"}>
      {data &&
        data.length > 0 &&
        data.map((item, index) => (
          <Link
            key={index}
            to="/store/product-view/:id"
            className="product-card position-relative"
          >
            <div className="wishlist-icon position-absolute">
              <button
                className="border-0 bg-transparent"
                onClick={() =>
                  dispatch(
                    addWishlist({
                      token: user.refreshToken,
                      data: { item: item._id },
                    })
                  )
                }
              >
                <img src="/assets/images/wish.svg" alt="..." />
              </button>
            </div>
            <div className="product-image">
              {item.images.slice(0, 2).map((image, index) => (
                <img
                  key={index}
                  className="img-fluid"
                  src={image.image}
                  alt="..."
                />
              ))}
            </div>
            <div className="product-details">
              <h6 className="brand">{item.brand.name}</h6>
              <h5 className="product-title">{item.title}</h5>
              <Rating style={{ maxWidth: 90 }} value={item.totalRatings} />
              <p
                className={`description ${grid === 12 ? "d-block" : "d-none"}`}
              >
                {item.category.description}
              </p>
              <p className="price">$&nbsp;{item.price}</p>
            </div>
            <div className="action-bar position-absolute">
              <div className="d-flex flex-column gap-15">
                <button className="border-0 bg-transparent">
                  <img src="assets/images/view.svg" alt="..." />
                </button>
                <button className="border-0 bg-transparent">
                  <img src="assets/images/prodcompare.svg" alt="..." />
                </button>
                <button className="border-0 bg-transparent">
                  <img src="assets/images/add-cart.svg" alt="..." />
                </button>
              </div>
            </div>
          </Link>
        ))}
    </div>

And this is where I render it inside the main component

<Container classProp="featured-wrapper py-5 home-wrapper-2">
   <div className="row">
      <div className="col-12">
         <h4 className="section-heading">Featured Collection</h4>
      </div>
          <ProductCard data={featuredProducts} />
  </div>
</Container>

This is the Container component

const Container = (props) => {
  return (
    <section className={props.classProp}>
      <div className="container-xxl">{props.children}</div>
    </section>
  );
};

It appears in a column instead of using the grid system. Please how do I make the Home component display in a row.
enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    I moved the col-3 to be returned by the map function

    <div className="row">
       {data &&
         data.length > 0 &&
           data.map((item, index) => (
             <div key={index} className= "col-3">
                <Link
                  to="/store/product-view/:id"
                  className="product-card position-relative"
                >
                  ......
                </Link>
              </div>
            ))}
        </div>
    

  2. I think you are looking for nested grid layout here. Take a look at this example:

    <MainContainer className='container'>
      <div className='row'>
        <div className='col-12'>
          <Container className='container'>
            <div className='row'>
              <div className='col-12'>
                <h4 className="section-heading">Featured Collection</h4>
              </div>
            </div>
            <div className='row'>
              {products.map(product => <Product className='col-3'/>)}
            </div>
          </Container>
        <div/>
      </div>
    </MainContainer>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search