Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
How do I make my TableData react component reusable onClick when its only posting one under my table?

I am making a react expense tracker. I have my App then inside of it I have a Form component with a button. Then I have a TableData component I pass state input to through props. However When I send it over it doesn't post another table Row under the table it just stays at one. I figure I need to map something. Ive tried mapping the state input prop and passing it that way. But I'm not achieving what I want. Im not able to find what I need on google either. Any hints would be amazing thank you. Side note new to using stackOverflow so if I messed up my post at all apologies

<tr className='tableRow'>
<td>{props.userState.payment}</td>
<td>{props.userState.purchase}</td>
<td>{props.userState.date}</td>
<td>{props.userState.location}</td>
<td>{props.userState.price}</td>
<td><button onClick={onButtonClick}>X</button></td>
</tr>
 Above code is TableData.js

 Below code is in my Form.js
<TableData userState={formValues} 
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to have formValues as an array of row-objects, to map each object to each row.So when you add it, it will be pushed into the array and will be displayed in table.

Inside tableData, You should be mapping userState as below:

{props.userState?.map(rowItem => (
  <tr key={rowItem.id} className='tableRow'>  // pass any unique value(id) to key
    <td>{rowItem.payment}</td>
    <td>{rowItem.purchase}</td>
    <td>{rowItem.date}</td>
    <td>{rowItem.location}</td>
    <td>{rowItem.price}</td>
    <td><button onClick={onButtonClick}>X</button></td>
</tr>
))}

key is important in mapping - https://betterprogramming.pub/why-react-keys-matter-an-introduction-136b7447cefc

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda