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

133
Views
button onClick doesn't work when disabled=True is initialized (Reactjs)

I have a button which I initialize as disabled that I enable when another event happens. But when I click on it the onClick function isn't called.

<div className='button-parent'>
    <button id="saveButton" type="button" onClick={updateBill} disabled={true} className="button">Save</button>
</div>

I have the opacity change when it's enabled, so I'm sure it's enabled when I try to press it and it doesn't work.

I'm sure the function is fine as when I add the onClick to the parent element, it works fine.

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

0

Use a state to manage the disabled condition instead of hardcoding it to true.

const [isDisabled, setIsDisabled] = useState(true)

<button id="saveButton" type="button" onClick={updateBill} disabled={isDisabled} className="button">Save</button>

When your other event happens and you want to enable it just

setIsDisabled(false)
about 4 years ago · Juan Pablo Isaza Report

0

You can make something like this :

const [enable, setEnable] = useState(true);

<button id="saveButton" type="button" disabled={enable} className="button">Save</button>

You can call the function to update the state and you can use the following to update state :

setEnable(!enable).

This will toggle the state and enable or disable the button using the previous state.

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!