@homecode/ui 4.20.0 → 4.20.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -73,6 +73,11 @@ import * as resizeObserver from './src/tools/resizeObserver.js';
73
73
  export { resizeObserver };
74
74
  import * as queryParams from './src/tools/queryParams.js';
75
75
  export { queryParams };
76
+ export { useDebounce } from './src/hooks/useDebounce.js';
77
+ import 'react';
78
+ export { useThrottle } from './src/hooks/useThrottle.js';
79
+ export { useIsMounted } from './src/hooks/useIsMounted.js';
80
+ export { useListKeyboardControl } from './src/hooks/useListKeyboardControl.js';
76
81
  import * as Form_types from './src/components/Form/Form.types.js';
77
82
  export { Form_types as FormTypes };
78
83
  export { SubmitButtons } from './src/components/Form/SubmitButtons/SubmitButtons.js';
@@ -59,9 +59,14 @@ import '../Virtualized/List/ListScroll.styl.js';
59
59
  function Autocomplete(props) {
60
60
  const { className, inputWrapperClassName, value, onChange, size = 'm', getOptions, onSelect, debounceDelay = 300, inputProps = {}, popupProps = {}, } = props;
61
61
  const isMounted = useIsMounted();
62
- const [searchValue, setSearchValue] = useState(value);
63
62
  const [options, setOptions] = useState([]);
64
63
  const [isLoading, setIsLoading] = useState(false);
64
+ const searchValRef = useRef(value);
65
+ const [searchValue, _setSearchValue] = useState(value);
66
+ const setSearchValue = (val) => {
67
+ searchValRef.current = val;
68
+ _setSearchValue(val);
69
+ };
65
70
  const currentRequest = useRef('');
66
71
  // @ts-ignore
67
72
  const inputRef = useRef(null);
@@ -118,7 +123,13 @@ function Autocomplete(props) {
118
123
  }
119
124
  }, debounceDelay);
120
125
  useEffect(() => {
121
- setSearchValue(value);
126
+ if (value !== searchValRef.current) {
127
+ if (isOpen)
128
+ fetchOptions(value);
129
+ }
130
+ else {
131
+ setSearchValue(value);
132
+ }
122
133
  }, [value]);
123
134
  const optionsList = useMemo(() => {
124
135
  if (!options.length)
@@ -0,0 +1,8 @@
1
+ import { useCallback } from 'react';
2
+ import debounce from '../tools/debounce.js';
3
+
4
+ function useDebounce(fn, delay) {
5
+ return useCallback(debounce(fn, delay), [fn, delay]);
6
+ }
7
+
8
+ export { useDebounce };
@@ -0,0 +1,5 @@
1
+ export * from './useDebounce';
2
+ export * from './useEvent';
3
+ export * from './useThrottle';
4
+ export * from './useIsMounted';
5
+ export * from './useListKeyboardControl';
@@ -0,0 +1 @@
1
+ export declare function useDebounce(fn: (...args: any[]) => void, delay: number): any;
@@ -1,3 +1,4 @@
1
1
  export * from './components';
2
2
  export * from './services';
3
3
  export * from './tools';
4
+ export * from './hooks';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homecode/ui",
3
- "version": "4.20.0",
3
+ "version": "4.20.2",
4
4
  "description": "React UI components library",
5
5
  "scripts": {
6
6
  "test": "jest",