Skip to content

Commit

Permalink
[@mantine/hooks] use-interval: Ensure that only one running interval …
Browse files Browse the repository at this point in the history
…can be rutting at a time (#2093)
  • Loading branch information
melloware committed Aug 12, 2022
1 parent 27c0f8f commit e449ac2
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 e449ac2

Please sign in to comment.