@pdg/react-form 1.0.18 → 1.0.19

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/index.js CHANGED
@@ -7529,6 +7529,13 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
7529
7529
  return multiple ? [] : null;
7530
7530
  }
7531
7531
  }, [value, multiple, items]);
7532
+ // Function ----------------------------------------------------------------------------------------------------------
7533
+ var showOnGetItemLoading = React.useCallback(function () {
7534
+ setIsOnGetItemLoading(true);
7535
+ }, []);
7536
+ var hideOnGetItemLoading = React.useCallback(function () {
7537
+ setIsOnGetItemLoading(false);
7538
+ }, []);
7532
7539
  // Effect ----------------------------------------------------------------------------------------------------------
7533
7540
  React.useEffect(function () {
7534
7541
  if (value !== initValue) {
@@ -7537,12 +7544,18 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
7537
7544
  onValueChange(name, value);
7538
7545
  }
7539
7546
  if (!async && onLoadItems) {
7540
- setIsOnGetItemLoading(true);
7547
+ showOnGetItemLoading();
7541
7548
  onLoadItems().then(function (items) {
7542
7549
  setItems(items);
7543
- setIsOnGetItemLoading(false);
7550
+ hideOnGetItemLoading();
7544
7551
  });
7545
7552
  }
7553
+ return function () {
7554
+ if (asyncTimerRef.current) {
7555
+ clearTimeout(asyncTimerRef.current);
7556
+ asyncTimerRef.current = null;
7557
+ }
7558
+ };
7546
7559
  // eslint-disable-next-line react-hooks/exhaustive-deps
7547
7560
  }, []);
7548
7561
  useFirstSkipEffect$1(function () {
@@ -7553,17 +7566,20 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
7553
7566
  onValueChange(name, value);
7554
7567
  }, [value]);
7555
7568
  React.useEffect(function () {
7556
- if (asyncTimerRef.current) {
7557
- clearTimeout(asyncTimerRef.current);
7558
- asyncTimerRef.current = null;
7559
- }
7560
7569
  if (async && onLoadItems && inputValue != null) {
7570
+ if (asyncTimerRef.current) {
7571
+ clearTimeout(asyncTimerRef.current);
7572
+ asyncTimerRef.current = null;
7573
+ }
7574
+ showOnGetItemLoading();
7561
7575
  asyncTimerRef.current = setTimeout(function () {
7562
7576
  asyncTimerRef.current = null;
7563
- setIsOnGetItemLoading(true);
7564
- onLoadItems(inputValue).then(function (items) {
7577
+ onLoadItems(inputValue)
7578
+ .then(function (items) {
7565
7579
  setItems(items);
7566
- setIsOnGetItemLoading(false);
7580
+ })
7581
+ .finally(function () {
7582
+ hideOnGetItemLoading();
7567
7583
  });
7568
7584
  }, 300);
7569
7585
  }