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

144
Views
Cannot use images with props in React

I'm trying to send an image as a prop from

import React from "react";
import "./home.css";
import Product from "./Product";

function Home() {
  return (
    <div className="home">
      <div className="home-container">
        <img
          className="home-image"
          src={require("./nathan-oakley-gj1dnc7yRG0-unsplash.jpg")}
          alt=""
        />
        <div className="home-row">
          <Product
            title="Sofa Couch"
            price={5000}
            image={"./phillip-goldsberry-fZuleEfeA1Q-unsplash.jpg"}
            rating={5}
          />
          <Product />
        </div>

        <div className="home-row">
          <Product />
          <Product />
          <Product />
        </div>

        <div className="home-row">
          <Product />
          <Product />
        </div>
      </div>
    </div>
  );
}

export default Home;

in the home-row class to

import React from "react";
import "./product.css";

function Product({ title, image, price, rating }) {
  return (
    <div className="product">
      <div className="product-info">
        <p>{title}</p>
        <p>
          <small>$</small>
          <strong>{price}</strong>
        </p>
        <div className="product-rating">
          {Array(rating)
            .fill()
            .map((_, i) => (
              <p>*</p>
            ))}
        </div>
      </div>
      <img src={require(`${image}`)} alt="" />
      <button>Add to Basket</button>
    </div>
  );
}

export default Product;

this file. But the image is not showing. Even if I remove require it doesn't show up. Earlier I was using a local image and it was working with require. But this doesn't.

When I inspect it with console, it says uncaught error, cannot find module 'image name'.

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!