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

149
Views
Counter inside an onClick function

EDIT: deleted due to qustion being outdated

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

0

Looks like you may be better off with a button to add new upload items to the list. Here's a quick example.

 const { useState } = React; function Example() { // Simple counter in state. You may prefer this to be // an array, or an object that you can add item objects to const [counter, setCounter] = useState(0); // Returns an array of divs based on the counter value function getDivs() { const divs = []; for (let i = 0; i < counter; i++) { divs.push(<div>{i + 1}</div>); } return divs; } // Updates the counter function handleClick() { setCounter(counter + 1); } return ( <div> <div className="divs"> {getDivs()} </div> <div className="counter">Div count: {counter}</div> <button type="button" onClick={handleClick}> Add new div </button> </div> ); } ReactDOM.render( <Example />, document.getElementById('react') );
 .divs { border: 1px solid #676767; padding-left: 0.3em; } .divs, .counter { margin-bottom: 1em; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js"></script> <div id="react"></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!