Implement a useCountdown hook that manages a countdown.
exportdefaultfunction Component() {
const { count, start, stop, reset } = useCountdown({ countStart: 10 });
return (
<div>
<p>Countdown: {count}</p>
<button onClick={start}>Start</button>
<button onClick={stop}>Stop</button>
<button onClick={reset}>Reset</button>
</div>
);
}
The hook accepts an object with the following properties:
countStart: number: The initial value of the countdowncountStop: number: The value at which the countdown should stop. This defaults to 0intervalMs: number: The interval (in milliseconds) at which the countdown should decrease. This defaults to 1000isIncrement: boolean: A flag to indicate whether the countdown should increment instead of decrement, defaults to falseThe hook returns an object with the following properties:
count: number: The current value of the countdownstart: () => void: A function that starts the countdownstop: () => void: A function that stops the countdownreset: () => void: A function that resets the countdown to countStart