1

From this code I get a 4 cards however I want to add a different photo to each card but using props I wanted to add in the path from the prop but I am getting no photo to render

I am new to react sorry if this is a silliy question I am having trouble finding a clear answer in docs.

function Case(photo) {
  return (
    <div className="pr-3">
      <div class="max-w-sm bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700">
        <a href="#">
          <img class="rounded-t-lg" src={photo} alt="" />
        </a>
        <div class="p-5">
          <a href="#">
            <h5 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white">
              Noteworthy technology acquisitions 2021
            </h5>
          </a>
          <p class="mb-3 font-normal text-gray-700 dark:text-gray-400">
            Here are the biggest enterprise technology acquisitions of 2021 so
            far, in reverse chronological order.
          </p>
          <a
            href="#"
            class="inline-flex items-center px-3 py-2 text-sm font-medium text-center text-white bg-blue-700 rounded-lg hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"
          >
            Read more
            <svg
              aria-hidden="true"
              class="w-4 h-4 ml-2 -mr-1"
              fill="currentColor"
              viewBox="0 0 20 20"
              xmlns="http://www.w3.org/2000/svg"
            >
              <path
                fill-rule="evenodd"
                d="M10.293 3.293a1 1 0 011.414 0l6 6a1 1 0 010 1.414l-6 6a1 1 0 01-1.414-1.414L14.586 11H3a1 1 0 110-2h11.586l-4.293-4.293a1 1 0 010-1.414z"
                clip-rule="evenodd"
              ></path>
            </svg>
          </a>
        </div>
      </div>
    </div>
  );
}

const ShowCase = () => {
  return (
    <div>
          <section className="flex flex row pt-12">
            <Case photo={imgs / showcase1.png} />
            <Case />
            <Case />
            <Case />
          </section>
        </div>
  );
};

export default ShowCase;

Carlos
  • 111
  • 8
  • You have to first import your image from the correct file directory and then pass it as props between two functional components. This might help you - https://stackoverflow.com/questions/71075028/how-to-display-images-using-props-in-react – Roshan Kanwar Feb 09 '23 at 19:25

1 Answers1

1

first, import images in parent component and pass to children as a props :

import img1 from 'src1.png';
import img2 from 'src2.png';

function Parent(){
    return (<>
        <Children image={img1} />
        <Children image={img2} />
    <>);
}

then, in children component, you can use images:

function Children({image}){
    return (<img src={image} />);
}

other way is using of absolute path like : https://example.com/img.png

 function Parent(){
        return (<>
            <Children image={'http://example.com/img1.png'} />
            <Children image={'http://example.com/img1.png'} />
        <>);
    }
Abbas Bagheri
  • 790
  • 5
  • 10