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

alkem-io / client-web / #8388

18 Jul 2024 07:14AM UTC coverage: 5.75%. First build
#8388

Pull #6612

travis-ci

Pull Request #6612: Package updates to reduce vulnerabilities

188 of 9965 branches covered (1.89%)

Branch coverage included in aggregate %.

0 of 13 new or added lines in 7 files covered. (0.0%)

1407 of 17775 relevant lines covered (7.92%)

0.19 hits per line

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

7.14
/src/domain/shared/utils/useLoadingState.ts
1
import { useEffect, useRef, useState } from 'react';
2

3
export interface Callback<Args extends unknown[], Result> {
4
  (...args: Args): Promise<Result>;
5
}
6

7
export type Provided<Args extends unknown[], Result> = [
8
  callback: Callback<Args, Result>,
9
  isLoading: boolean,
10
  error: Error | undefined
11
];
12

13
const useLoadingState = <Args extends unknown[], Result>(
1✔
14
  originalCallback: Callback<Args, Result>
15
): Provided<Args, Result> => {
16
  const [isLoading, setIsLoading] = useState(false);
×
17
  const [error, setError] = useState<Error>();
×
18

19
  const isMountedRef = useRef(true);
×
20

×
21
  useEffect(() => {
×
22
    isMountedRef.current = true;
×
23

NEW
24
    return () => {
×
NEW
25
      isMountedRef.current = false;
×
26
    };
27
  }, []);
×
28

29
  const callback = async (...args: Args) => {
×
30
    if (isMountedRef.current) setIsLoading(true);
31
    try {
32
      return await originalCallback(...args);
33
    } catch (error) {
×
34
      if (error instanceof Error) {
35
        setError(error);
36
      }
37
      throw error;
38
    } finally {
39
      if (isMountedRef.current) setIsLoading(false);
40
    }
41
  };
42

43
  return [callback, isLoading, error];
44
};
45

46
export default useLoadingState;
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

© 2026 Coveralls, Inc