feat: init
This commit is contained in:
19
apps/web/core/hooks/use-timer.tsx
Normal file
19
apps/web/core/hooks/use-timer.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
const TIMER = 30;
|
||||
|
||||
const useTimer = (initialValue: number = TIMER) => {
|
||||
const [timer, setTimer] = useState(initialValue);
|
||||
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
setTimer((prev) => prev - 1);
|
||||
}, 1000);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
return { timer, setTimer };
|
||||
};
|
||||
|
||||
export default useTimer;
|
||||
Reference in New Issue
Block a user