Home > Net >  Disable Button for a period of time using React
Disable Button for a period of time using React

Time:01-29

I want that when the user clicks on this button, it will be disable for a period of time and then it will enable automatically

CodePudding user response:

const [disable, setDisable] = useState(false);
const handleDisable = () => {
setDisable(true);
setTimeout(() => {setDisable(false)}, 3000)
}
<button disabled={disable} onClick={handleDisable}>click me</Button>
  •  Tags:  
  • Related