Skip to content

Commit

Permalink
Fix mantinedev#2093: Interval hook ensure only 1 running timer
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Aug 12, 2022
1 parent 27c0f8f commit b67b6e5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/mantine-hooks/src/use-interval/use-interval.ts
Expand Up @@ -11,7 +11,7 @@ export function useInterval(fn: () => void, interval: number) {

const start = () => {
setActive((old) => {
if (!old) {
if (!old && !intervalRef.current) {
intervalRef.current = window.setInterval(fnRef.current, interval);
}
return true;
Expand All @@ -21,6 +21,7 @@ export function useInterval(fn: () => void, interval: number) {
const stop = () => {
setActive(false);
window.clearInterval(intervalRef.current);
intervalRef.current = undefined;
};

const toggle = () => {
Expand Down

0 comments on commit b67b6e5

Please sign in to comment.