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

alkem-io / client-web / #8587

06 Aug 2024 01:45PM UTC coverage: 5.823%. First build
#8587

Pull #6712

travis-ci

Pull Request #6712: Release 0.68.0

188 of 9893 branches covered (1.9%)

Branch coverage included in aggregate %.

12 of 309 new or added lines in 42 files covered. (3.88%)

1408 of 17516 relevant lines covered (8.04%)

0.19 hits per line

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

4.35
/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

NEW
19
  const isMountedRef = useRef(true);
×
20

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

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

29
  const callback = async (...args: Args) => {
×
NEW
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 {
NEW
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