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

261
Vistas
How to keep track of every state's update to be able to render on a list all the data that has been sent through a form

I am creating an app to keep track of expenses.

Before creating the server side. What I am trying to do is to render all information held in the state in a list format.

As I am not storing this data in a database. I wondered if there would be a way to do it without creating the database. I mean, just do this task dealing just with react.(I have to learn server side yet)

What I've done: I sent the data, data is the state created in , as props to component, and and in there, I created an empty array to push each property of the data object. After created the array, in the return of the List component, I map through that array to print all the information.

But obviously, once I type something, the previous data disappears.

What I am trying to achieve is what I've explained at the beginning.

How to keep track of all inputs and print all of them without losing the previous enter.

I am new to this. So, please, go easy on me :)


export default function Forms() {
    const [data, setData] = useState({
        concept:"",
        amount:"$",
        date:getCurrentDate(),
        select: "Income"
    })
    function handleChange(event){
        let name = event.target.name;
        let value = event.target.value;
        setData({...data,[name]:value})
    
      }


  return (
    <>
      <h2>Incomes - Outcomes</h2>
      <form className="form">
        <label>Concept:</label> 
        <input type="text" name="concept" value={data.concept} onChange={handleChange} />

        <label>Amount:</label>
        <input type="text" name="amount" value={data.amount} onChange={handleChange}/>

        <label>Date:</label>
        <input  name="date" value={data.date} onChange={handleChange}/>

        <label>Select type of expense:</label>
        <select name="select" value={data.type} onChange={handleChange}>
            <option value="Income">Income</option>
            <option value="Outcome">Outcome</option>
        </select>
       

        
      </form>
    <List data={data}/>
    </>
  );
}


export default function List({ data }) {
 

  const arrayOfExpenses = [];
  
  Object.keys(data).forEach((key) => {
    arrayOfExpenses.push(key + ": " + data[key]);
  })

    function handleSubmit(event) {
      event.preventDefault();
    }



  return (
    <div>
      <button onClick={handleSubmit}>Submit</button>
    {arrayOfExpenses.map((element, index) =>(
        <ul key={index}>
            <li>{element}</li>
        </ul>
    )
        
    )}
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza
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