I have a button that I disabled via a boolean variable. The variable works on first load but when the variable is updated the disabled attribute stays. How do I update it so it gets removed?
My current code is like this:
var isDisabled = true;
return (
<>
<button onClick={() => isDisabled = false}>Enable Second Button</button>
<button disabled={isDisabled}>Second Button</button>
</>
)
2
Answers
I fixed it by using React useState instead of normal variables. Instead of:
I did
Ensure that you have correctly bound the boolean variable to the disabled attribute of the button in your HTML code. The binding should be two-way so that changes to the variable reflect in the attribute and vice versa.