效果图
代码实现
import { useState } from "react";
const Home = () => {
const [time, setCount] = useState(10)
const timeClick = () => {
let times = time;
let timer = setInterval(function () {
if (times < 1) {
setCount(10)
clearInterval(timer);
} else {
times -= 1;
setCount(times);
}
}, 1000);
};
return (
<div>
<button onClick={() => timeClick()}>{time}</button>
</div>
);
}
export default Home;