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

196
Views
Cómo obtener la identificación del componente en otro componente en componentes funcionales

soy nuevo en reaccionar

Estoy tratando de obtener una identificación de tarjeta única de una matriz de tarjetas. No estoy entendiendo cómo hacerlo.

Mi código se ve así.

tarjeta.js

 import React from "react"; const cardDetailsClick = (ID) => { console.log("card id is " + ID); }; const Card = ({ title, id }) => { return ( <div className="card"> <div className="description"> <h1>{title}</h1> <button onClick={onBtnClick}>Know more</button> </div> </div> ); };

app.js: aquí quiero la identificación de la tarjeta en la que hago clic

 import React from "react"; const [cards, setCards] = useState([]); // I have setCards to be 20 different cards each has a unique id. onBtnClick = (id) => { console.log(id); // I want the id of the card button I click here }; const Cards = () => { return <div>{cards.length > 0 && cards.map((card) => <Card key={card.id} {...card} />)}</div>; }; export default Cards;

Quiero obtener la identificación de esa tarjeta en la que se hace clic en el botón.

¡La ayuda sería apreciada!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Prueba esto:

 const cardDetailsClick = (e,ID) => { console.log("card id is " + ID); }; const Card = ({ title, id }) => { return ( <div className="card"> <div className="description"> <h1>{title}</h1> <button onClick={(e)=> onBtnClick(e,id)}>Know more</button> </div> </div> ); };
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!