如何以分钟和秒显示倒数计时器。现在我只能以秒为单位显示计时器,但我想同时显示分钟和秒。
目前我的倒数计时器以这种方式显示,Countdown: 112
但我希望它像Countdown: 1: 52
import React from "react";
export default function App() {
const [counter, setCounter] = React.useState(120);
React.useEffect(() => {
counter > 0 && setTimeout(() => setCounter(counter - 1), 1000);
}, [counter]);
return (
<div className="App">
<div>Countdown: {counter === 0 ? "Time over" : counter}</div>
</div>
);
}