amrlabib / react-timer-hook

React timer hook

Home Page:https://www.npmjs.com/package/react-timer-hook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handling multiple timers

AmauryLiet opened this issue · comments

Hello,
First of all thanks a lot for the lib and your continuous work on it


It would be highly valuable for my project to be able to handle a dynamic number of timers (dynamicity making it incompatible with calling useTimer n-times)

The API could look like this:

export function useMultipleTimers(settings: TimerSettings): TimerResult

interface TimerSettings {
    // no expiryTimestamp: it MUST be defined at runtime (start or restart), making start & restart identical functions
    onExpire?: (timerId) => void;
}

interface TimerResult {
    getRemainingTime: (timerId: string) => {
        seconds: number;
        minutes: number;
        hours: number;
        days: number;
    };

    getIsRunning: (timerId: string) => boolean;
    start: (timerId: string, newExpiryTimestamp: Date, autoStart?: boolean) => void;
    pause: (timerId: string) => void;
    resume: (timerId: string) => void;
}

I could give it a go implementing it, but I am looking forward for your opinion beforehand ;)

Thanks!