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

257
Views
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
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!