Here’s how you disable a button using React
When you need to disable a button using React, you can simply add the disabled
prop to your <button>
element:
function App() {
return <button disabled={true}>Click me!</button>;
}
Knowing this, you can easily modify the code according to your requirements to disable the <button>
.
For example, you may want to disable a <button>
after it has been clicked. You can do so by adding a state that controls the value of disabled
prop. Let’s name the state disable
and set its default value to false
:
const [disable, setDisable] = React.useState(false);
After that, you need to use the disable
state value as the value of disabled
prop in the <button>
element.
#react