1.0.1 • Published 11 months ago

react-use-multi-timer v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

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;