点击一个button按钮,开始禁用,多少秒后解除禁用
import React, { useState } from "react";
export const ButtonDisabled: React.FC = () => {
const [count, setCount] = useState(6)
const [disabled, setDisabled] = useState(false)
const onChangeHandle = (count: number) => {
if (count > 0) {
setCount(count--)
setTimeout(() => {
onChangeHandle(count)
}, 1000)
setDisabled(true)
} else {
setDisabled(false)
setCount(6)
}
}
return (
<>
<button disabled={disabled} onClick={() => onChangeHandle(count)}>{count}</button>
</>
)
}