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

141
Views
Rendering React Component Multiple Times onClick (Expense Tracker)

I am trying to render my form inputs multiple times through a component. I did 3 tutorials and am trying to apply what I learned from that to make this. However, it's getting a bit confusing trying to transfer state onSubmit. onSubmit I'm taking state from the form and using the spread operator to place it into a expenses state. Then from there, I am trying to put a map inside of my ExpenseTable.js to render multiple Expenses.js components. I've probably spent way too much time on a basic app. So any help would be appreciated! App.js

const [formValues, setFormValues] = useState(initialValues);
const [expenses, setExpenses] = useState([]);

  return (
    <div className="App">
      <header>
        <h1>Bloop</h1>
      </header>
      <Form formValues={formValues} setFormValues={setFormValues} expenses={expenses} setExpenses={setExpenses} />
      <ExpenseTable setExpenses={setExpenses} expenses={expenses}/> </div> 

Form.js Functions

 
const onHandleChange = (e) => {
  const value = e.target.value;
  setFormValues({...formValues,
  [e.target.name]: value
  });
}

const onSubmit = (e) => {
  e.preventDefault();

setExpenses([
  ...expenses, { id: Math.random() * 1000},
])
 setFormValues('');
};

ExpenseTable.js

  const userRows = expenses.map(expense => (
    <Expense key={expense.id} expense={expense} />
  ));

  return(
<div className="expense-container">
      <ul className="expense-list">
       {userRows}
      </ul> </div> 

Expense.js



  return(
    <div style={{ display: 'flex', justifyContent: 'spaceBetween'}}>
    <p>{payment}</p>
    <p>{purchase}</p>
    <p>{date}</p>
    <p>{location}</p>
    <p>{price}</p>
  </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!