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

169
Views
How to make same button to increase count and revert back to its previous state in React (useState)?

I want to change the count by one and make the same button revert back to its previous state on click.

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

0

export const CountButton = () => {
  previousState = 100;
  const [count, setCount] = useState(false);
  return(
   <div>
     <button onClick={() => setCount(!count)}>Click Me!</button>
     <div>{count ? previousState + 1 : previousState }</div>
   </div>
  )
}

This code will increase the vote by one and then revert on the second click.

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!