跳至主要內容

Countdown

宋玉小于 1 分钟分类

const { useState, useEffect } = React;
const App = (props) => {
const [count, setCount] = useState(100);
useEffect(() => {
  setInterval(() => {
	setCount(count - 1);
  }, 1000);
}, [count]);
return (
  <div>
	<h1>{props.title}</h1>
	<div>{count}</div>
	<div>
	  <button>开始</button>
	  <button>结束</button>
	  <button>暂停</button>
	</div>
  </div>
);

Countdown DEMOopen in new window