Co-authored-by: Bavisetti Narayan <[email protected]> Co-authored-by: NarayanBavisetti <[email protected]> Co-authored-by: Bavisetti Narayan <[email protected]> Co-authored-by: Nikhil <[email protected]> Co-authored-by: M. Palanikannan <[email protected]> Co-authored-by: Lakhan Baheti <[email protected]> Co-authored-by: Dakshesh Jain <[email protected]> Co-authored-by: Aaryan Khandelwal <[email protected]>
20 lines
395 B
TypeScript
20 lines
395 B
TypeScript
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;
|