useCountdown
timer hook
#129
vincerubinetti
started this conversation in
Show and tell
Replies: 3 comments 1 reply
-
Example usage, and my personal use case why I found it useful: const Component = () => {
const [playing, setPlaying] = useState(false);
const [recording, setRecording] = useState(false);
const [countdown, startCountdown, stopCountdown] = useCountdown(3);
return (
<>
<CheckButton
tooltip={recording ? "Disarm recording" : "Arm recording"}
checked={recording}
onChange={(value) => {
if (countdown) stopCountdown();
setRecording(value);
}}
>
{countdown ? Math.floor(countdown + 1).toFixed(0) : "🔴"}
</CheckButton>
<CheckButton
tooltip={playing ? "Pause" : "Play"}
checked={playing}
onChange={(value) => {
if (countdown) stopCountdown();
else if (value) {
if (recording) startCountdown(() => setPlaying(true));
else setPlaying(true);
} else setPlaying(false);
}}
>
{playing ? "⏸️" : "▶️"}
</CheckButton>
</>
);
}; |
Beta Was this translation helpful? Give feedback.
0 replies
-
Very Good. Notwithstanding, I consider we can enhance the original |
Beta Was this translation helpful? Give feedback.
0 replies
-
Maybe something like this. Would you like to put forward a pull request to include it to the lib? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Not the same as the already built-in
useCountDown
hook. This is more like auseTimer
hook. Might be useful to someone, or maybe the maintainers want to include it in the library.Related: #128
Beta Was this translation helpful? Give feedback.
All reactions