Here is the code to disable the button. I do not understand why the button is not disabled. Please help me find where it went wrong.
import { useState } from 'react';
const App = () => {
const [value, setValue] = useState('');
const handleDisable = (e) => {
setValue(e.target.value);
};
return (
<div className='App'>
<h1>Hello CodeSandbox</h1>
<h3> Disable Button</h3>
<input type='text' onChange={handleDisable} value={value} />
<button disabled={value.length < 1}>
Submit
</button>
</div>
);
};
export default App;
CodePudding user response:
try checking for <button disabled={value.length === 0}>
CodePudding user response:
Hi passion, your coding is working as well. I check your code in the code sandbox. It's working as well.
