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

137
Views
clicking a button second time, getting different result

When a button (material ui) is clicked for a second time, I want that button to be disabled (disabled={true}). I did not find any example related to this on StackOverflow.

<Button
  onClick={this.startDraw.bind(this)}
  disabled={}
  startIcon={<Brush />}
>

At first, the button is clickable. When it is clicked, something happens, but when this same button is clicked a second time, the button should be disabled (cannot be clicked anymore).

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

0

For Class component use

    state = {
    count: 0
    };
this.setState({ count: count + 1 }); // use this on your button click

and for the button part

   <Button
    onClick={this.startDraw.bind(this)}
    disabled={count == 2}
    startIcon={<Brush />}
  />

for functional component use this approach


   const [count , setCount ] = useState(0);
   setCount(count + 1) // use this on your button call

    <Button
    onClick={this.startDraw.bind(this)}
    disabled={count == 2}
    startIcon={<Brush />}
/>

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!