• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mints-components / hooks / 13319939355

14 Feb 2025 12:36AM CUT coverage: 96.569% (-0.2%) from 96.809%
13319939355

push

github

mintsweet
feat: add a new hook useQueryParams

62 of 68 branches covered (91.18%)

Branch coverage included in aggregate %.

15 of 16 new or added lines in 2 files covered. (93.75%)

135 of 136 relevant lines covered (99.26%)

13.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.94
/src/use-simulate-progress.ts
1
import { useState, useEffect, useRef } from 'react';
16✔
2

3
type func = (...args: any[]) => void;
4

5
export const useSimulateProgress = (
16✔
6
  duration: number,
7
  onComplete: func,
8
): [number, func, func] => {
9
  const [progress, setProgress] = useState(0);
20✔
10
  const intervalRef = useRef<any>(null);
20✔
11

12
  const startProgress: func = (...args) => {
20✔
13
    if (intervalRef.current) return;
6!
14

15
    let progressValue = 0;
6✔
16
    intervalRef.current = setInterval(() => {
6✔
17
      progressValue += 5;
80✔
18
      setProgress(progressValue);
80✔
19

20
      if (progressValue >= 100) {
80✔
21
        clearInterval(intervalRef.current);
2✔
22
        intervalRef.current = null;
2✔
23
        onComplete(...args);
2✔
24
      }
25
    }, duration / 20);
26
  };
27

28
  const resetProgress = () => {
20✔
29
    if (intervalRef.current) {
2✔
30
      clearInterval(intervalRef.current);
2✔
31
      intervalRef.current = null;
2✔
32
    }
33
    setProgress(0);
2✔
34
  };
35

36
  useEffect(() => {
20✔
37
    return () => {
8✔
38
      if (intervalRef.current) {
8✔
39
        clearInterval(intervalRef.current);
2✔
40
      }
41
    };
42
  }, []);
43

44
  return [progress, startProgress, resetProgress];
20✔
45
};
46

47
export default useSimulateProgress;
16✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc