react-use-multi-timer
v1.0.1
Published
A custom React hook for managing multiple countdown timers using Web Workers. react-use-countdown-timers allows you to easily start, stop, and track multiple timers that count down to zero, making it perfect for use cases like modal timers, task countdown
Downloads
12
Maintainers
Readme
react-use-multi-timer
react-use-multi-timer
is a React hook for managing multiple timers with ease.
Installation
You can install the package using npm or yarn:
npm install react-use-multi-timer
# or
yarn add react-use-multi-timer
import React from 'react';
import useTextOrderTimer from 'react-use-multi-timer';
function App() {
const { startAllModalHandlerTimer, stoptAllModalHandlerTimer, timerStates } = useTextOrderTimer();
const handleStartTimer = () => {
// Duration in seconds for the timer
const durationInSeconds = 10;
// Start a timer with ID "YourTimerID" that counts down from 10 seconds
startAllModalHandlerTimer("YourTimerID", durationInSeconds, () => {
console.log("Timer completed");
});
};
const handleStopTimer = () => {
// Stop a timer with ID "YourTimerID"
stoptAllModalHandlerTimer("YourTimerID");
};
return (
<div className="App">
<button onClick={handleStartTimer}>Start Timer</button>
<button onClick={handleStopTimer}>Stop Timer</button>
{/* Display the remaining time in seconds for the timer with ID "YourTimerID" */}
<div>Time left: {timerStates["YourTimerID"]}</div>
</div>
);
}
export default App;