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

ringcentral / ringcentral-js-widgets / 21017357600

15 Jan 2026 02:19AM UTC coverage: 61.994% (-1.1%) from 63.06%
21017357600

push

github

web-flow
misc: sync features and bugfixes from 8f9fbb5dfe (#1784)

* misc: sync crius

* chore: update babel-setting deps

* feat(core): update logger and add fromWatch

* misc: fix tsconfig

* misc: fix tsconfig

* misc: update eslint-settings and new eslint-plugin-crius package

* chore: remove ci and nx from package.json

* feat(i18n): new getAcceptLocaleMap and preudo string support

* chore: add preudo i18n

* misc(locale-loader): convert to ts, new format support

* misc(locale-settings): use ts

* chore: add format test in phone number lib

* feat(react-hooks): add more hooks

* chore: add comments

* misc: add more mock files

* misc: update test utils

* misc: update utils

* chore: update tsconfig

* misc: update i18n string, and convert to ts

* feat: update ui components, support emoji input, new video setting ui

* feat: new rcvideo v2 module

* feat: use new subscription register api

* misc(commons): update enums/interfaces

* misc: update Analytics lib

* misc: upgrade uuid and update import

* misc(commons): update formatDuration lib

* misc(test): add test steps

* chore: update tests and more feature tests

* misc: update demo project

* misc: update cli template

* misc: fix deps issue

* misc: remove glip widgets package

* misc: fix wrong import path

* misc: limit jest worker memory

* chore: use npm trusted-publishers

10285 of 18150 branches covered (56.67%)

Branch coverage included in aggregate %.

986 of 2186 new or added lines in 228 files covered. (45.11%)

44 existing lines in 23 files now uncovered.

17404 of 26514 relevant lines covered (65.64%)

167640.7 hits per line

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

94.44
/packages/react-hooks/src/useAsyncState.ts
1
import {
2
  useDebounce,
3
  useEventCallback,
4
  useRefState,
5
  useDepsChange,
6
} from '@ringcentral/spring-ui';
7
import { useRef } from 'react';
8

9
/**
10
 * Custom hook for managing async control state to avoid too many rerender and async cause input cursor jump.
11
 *
12
 * use for update value in sync way when using `updateState` method,
13
 * in typing mode, input value will not update the value immediately, that will wait user not typing for 500ms then update the control value.
14
 *
15
 * `updateState(value, false)` will trigger update immediately, which will cancel the debounce 500ms delay.
16
 *
17
 * @param inputValue - The value for the control state.
18
 * @param asyncOnChange - The async function to handle the value change.
19
 */
20
export const useAsyncState = <T = string>(
226✔
21
  inputValue: T,
22
  asyncOnChange?: (value: T) => void,
23
) => {
24
  const [state, _setState] = useRefState<T>(inputValue);
18✔
25

26
  const debouncingRef = useRef(false);
18✔
27
  const debounceSetState = useDebounce(() => {
18✔
28
    setState(inputValue);
3✔
29
  }, 500);
30

31
  const setState = useEventCallback((val: T, rerender?: false | undefined) => {
18✔
32
    debouncingRef.current = false;
5✔
33
    debounceSetState.cancel();
5✔
34
    _setState(val, rerender);
5✔
35
  });
36

37
  useDepsChange(() => {
18✔
38
    if (state.current === inputValue) {
11✔
39
      debouncingRef.current = false;
7✔
40

41
      return;
7✔
42
    }
43

44
    // when be empty from outside, cancel previous debounce prevent update show again
45
    if (state.current !== '' && inputValue === '') {
4✔
46
      setState(inputValue, false);
1✔
47
    } else if (debouncingRef.current) {
3!
48
      // use debounce to avoid too many rerender and async cause input cursor jump
49
      debounceSetState();
3✔
50
    } else {
NEW
51
      setState(inputValue, false);
×
52
    }
53
  }, [inputValue]);
54

55
  const updateState = useEventCallback(
18✔
56
    (
57
      value: T,
58
      /**
59
       * update in typing mode or not, when `false` will trigger update immediately
60
       *
61
       * @default true
62
       */
63
      typing: boolean = true,
2✔
64
    ) => {
65
      if (typing) {
5✔
66
        debouncingRef.current = value !== '';
4✔
67
        _setState(value);
4✔
68
      } else {
69
        setState(value);
1✔
70
      }
71

72
      asyncOnChange?.(value);
5✔
73
    },
74
  );
75

76
  return [state.current, updateState] as const;
18✔
77
};
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