Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-05-13· OpenAIAi2 WildChat-4.8M (AI2)

how to make only two cards with two different images in the following jsx file: import…

  1. User

    how to make only two cards with two different images in the following jsx file: import "./Projects.css"; import { images } from "../../images/images.js"; import { useState } from "react";

    const Projects = ({ projectsProps }) => {   const [imgs, setImgs] = useState([     {       id: 1,       value: images.antools,     },     {       id: 2,       value: images.blueCollar,     },   ]);

      const generateDesc = () =>     projectsProps.cards.map((el) =>       imgs.map((img) => (                               <img               src={img.value}               alt=""               className="projects__cards-card-pic-img"             />                                 {el.title}             {el.text}                           {el.stack.map((element) => (                 <span                   key={Math.random()}                   className="projects__cards-card-desc-stack-span"                 >                   {element}                               ))}                                       <a                 href={el.liveLink}                 target="_blank"                 className="projects__cards-card-desc-source-link"               >                                   Live                                 <img                   className="projects__cards-card-desc-source-link-img"                   src={images.live_icon}                   alt=""                 />                             <a                 href={el.codeLink}                 target="_blank"                 className="projects__cards-card-desc-source-link"               >                                   Code                                 <img                   className="projects__cards-card-desc-source-link-img"                   src={images.github_icon}                   alt=""                 />                                                   ))     );

      return (                             Portfolio                       Each project is a unique piece of development                           {generateDesc()}             ); };

    export default Projects;

  2. Assistant

    Sure! The goal here is to generate only two cards with two different images. Here's how you can modify your code to achieve this:

    1. Ensure that only two cards are generated based on your projectsProps.
    2. Make sure that each card gets a unique image from your imgs state array.

    Below is the modified JSX code to create only the two cards with unique images:

    import "./Projects.css";
    import { images } from "../../images/images.js";
    import { useState } from "react";
    
    const Projects = ({ projectsProps }) => {
      const [imgs] = useState([
        {
          id: 1,
          value: images.antools,
        },
        {
          id: 2,
          value: images.blueCollar,
        },
      ]);
    
      // Ensure that the generated descriptions/cards are limited to 2
      const generateDesc = () => {
        return projectsProps.cards.slice(0, 2).map((el, index) => (
          <div key={el.id} className="projects__cards-card">
            <div className="projects__cards-card-pic">
              <img
                src={imgs[index].value}
                alt=""
                className="projects__cards-card-pic-img"
              />
            </div>
            <div className="projects__cards-card-desc">
              <h2 className="projects__cards-card-desc-title">{el.title}</h2>
              <p className="projects__cards-card-desc-text">{el.text}</p>
              <div className="projects__cards-card-desc-stack">
                {el.stack.map((element) => (
                  <span
                    key={Math.random()}
                    className="projects__cards-card-desc-stack-span"
                  >
                    {element}
                  </span>
                ))}
              </div>
              <div className="projects__cards-card-desc-source">
                <a
                  href={el.liveLink}
                  target="_blank"
                  className="projects__cards-card-desc-source-link"
                  rel="noopener noreferrer"
                >
                  <p className="projects__cards-card-desc-source-link-text">Live</p>
                  <img
                    className="projects__cards-card-desc-source-link-img"
                    src={images.live_icon}
                    alt=""
                  />
                </a>
                <a
                  href={el.codeLink}
                  target="_blank"
                  className="projects__cards-card-desc-source-link"
                  rel="noopener noreferrer"
                >
                  <p className="projects__cards-card-desc-source-link-text">Code</p>
                  <img
                    className="projects__cards-card-desc-source-link-img"
                    src={images.github_icon}
                    alt=""
                  />
                </a>
              </div>
            </div>
          </div>
        ));
      };
    
      return (
        <div id="projects" className="projects">
          <div className="container projects__wrap">
            <div className="projects__desc">
              <p className="projects__desc-tag tag">Portfolio</p>
              <h2 className="projects__desc-title title">
                Each project is a unique piece of development
              </h2>
            </div>
            <div className="projects__cards">{generateDesc()}</div>
          </div>
        </div>
      );
    };
    
    export default Projects;
    

    In this code:

    • The generateDesc function slices the projectsProps.cards array to only include the first two elements.
    • It then maps over these two elements and assigns images in sequence from the imgs array.

    This will ensure that only two cards with two different images are generated.