Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda