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

122
Views
take out name of dynamically created cards react

I had created some cards from an array of objects, now I want to show popup data for each card differently. here is my code of printing

{data.carData.map( single=>(<li>{ <div  onClick={handleClick}><Card single={single}/></div>} </li>))}

for this, I want the card name onClick event, but when I pass anything in the handleClick react throw an error of too many re-renders.

if I do the same onClick event inside the card component and log it prints all the cards names one by one here is what is inside the card:

 function Card({single}) {
const [flowName, setflowName] = useState();
const handleClick=(e)=>{
    setflowName(e);
    return
}
console.log("loging name:",flowName);
return (
         <div className="main mb-2 z-0" onClick={handleClick(e=>single?.flowName)} >
       <div  className=" inner_main_container pt-4 px-8 bg-white shadow-lg rounded-lg ">
           <div className="flex justify-between">
               <div className="flex flex-row align-center">

               </div>
              
                   {single?.badge.map(badge=>(

                       <div className={"badge"} key={badge}>
                       <span className={badge==="Growth"?" badgeClrG":(badge==="Content"?"content":"badgeClrO")} key={badge}>{badge}</span>
                       </div>
                   )    )}
                   
           </div>
           <div className="flex justify-center">
           <img src={single?.image} alt={single?.flowName} />
           </div>
           <div >
               <div className={"mt-2 flex justify-center"}>
                   <h1>{single?.flowName}</h1>
               </div>
           </div>
        </div>
        </div>            

)   }   export default Card
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I suspect you're doing this when you're trying to pass a value:

single=>(<li>{ <div  onClick={handleClick(value)}><Card single={single}/></div>} </li>))}

Every time this is rendered, the function is invoked straight away, which causes another render and so on...

The solution is to wrap your handleClick call in another function:

single=>(<li>{ <div  onClick={()=>handleClick(value)}><Card single={single}/></div>} </li>))}
about 4 years ago · Juan Pablo Isaza Report
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!