Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
ReactJS, can't pass props to modal window

I'm trying to render a modal window when a user clicks on a product to find out more details. I created a modal component that is hidden by default, and clicking on the product triggers a function that makes the modal visible and gives it the props of name, price of the product etc. However, I only get an empty modal.

Container:

const Product = ({ imgUrl, nameUrl, priceUrl, id }) => {
  const [title, setTitle] = useState("");
  const [productId, setProductId] = useState("");
  const [price, setPrice] = useState("");
  const [img, setImg] = useState("");
  const [modalClassName, setModalClassName] = useState("hidden");

  const renderModalProduct = () => {
    setTitle(nameUrl);
    setPrice(priceUrl);
    setImg(imgUrl);
    setModalClassName("visible");
  };

  return (
    <div className="product">
      <div className="img-container">
        <img src={imgUrl} alt="product image" onClick={renderModalProduct} />
      </div>
      <div className="product-description">
        <p>{nameUrl}</p>
        <p>€ {priceUrl}</p>
      </div>
      <div className="button-container">
        <AddShoppingCartIcon className="btn" data-tip="Add to cart" />
        <FavoriteBorderIcon className="btn" data-tip="Add to Favorites" />
        {/* <ZoomInIcon className="btn" /> */}
      </div>
      <ReactTooltip type="light" border="true" borderColor="grey" />
      <ModalProduct
        imgUrl={imgUrl}
        nameUrl={nameUrl}
        priceUrl={priceUrl}
        id={id}
        modalClassName={modalClassName}
      />
    </div>
  );
};

Modal Component:

const ModalProduct = ({ title, productId, price, img, modalClassName }) => {
  return (
    <div className={`${modalClassName} modal-product`}>
      <p>{title}</p>
      <img src={img} alt="" />
      <p>{price}</p>
    </div>
  );
};

Any ideas? Thank you!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!