api-core-lib 12.0.18 → 12.0.20

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/client.cjs CHANGED
@@ -710,20 +710,32 @@ function useApiActionState(actionConfig, cacheKey, execute, input, enabled) {
710
710
  getClientSnapshot,
711
711
  getServerSnapshot
712
712
  );
713
+ const inputRef = (0, import_react4.useRef)(input);
714
+ (0, import_react4.useEffect)(() => {
715
+ inputRef.current = input;
716
+ }, [input]);
713
717
  const refetch = (0, import_react4.useCallback)(() => {
714
- execute(input);
715
- }, [execute, JSON.stringify(input)]);
716
- const refetchRef = (0, import_react4.useRef)(refetch);
718
+ execute(inputRef.current);
719
+ }, [execute]);
720
+ const previousInput = (0, import_react4.useRef)(JSON.stringify(input));
717
721
  (0, import_react4.useEffect)(() => {
718
- refetchRef.current = refetch;
719
- }, [refetch]);
722
+ const currentInputString = JSON.stringify(input);
723
+ if (previousInput.current === currentInputString) {
724
+ return;
725
+ }
726
+ if (enabled && state.called) {
727
+ console.log("[Query Changed] Input changed, refetching...");
728
+ refetch();
729
+ }
730
+ previousInput.current = currentInputString;
731
+ }, [input, enabled, state.called, refetch]);
720
732
  (0, import_react4.useEffect)(() => {
721
733
  if (enabled && actionConfig.autoFetch && !state.called && !state.loading) {
722
- refetchRef.current();
734
+ refetch();
723
735
  } else if (enabled && state.isStale && !state.loading) {
724
- refetchRef.current();
736
+ refetch();
725
737
  }
726
- }, [enabled, state.isStale, state.loading, state.called, actionConfig.autoFetch]);
738
+ }, [enabled, state.isStale, state.loading, state.called, actionConfig.autoFetch, refetch]);
727
739
  return state;
728
740
  }
729
741
  function useModuleContext() {
@@ -774,7 +786,7 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
774
786
  body: input,
775
787
  config: options2.config
776
788
  });
777
- console.log("[API Result]", result);
789
+ console.log("[API Result execute]", result);
778
790
  if (shouldCache) {
779
791
  globalStateManager.setState(cacheKey, (prev) => ({
780
792
  ...prev,
package/dist/client.js CHANGED
@@ -671,20 +671,32 @@ function useApiActionState(actionConfig, cacheKey, execute, input, enabled) {
671
671
  getClientSnapshot,
672
672
  getServerSnapshot
673
673
  );
674
+ const inputRef = useRef4(input);
675
+ useEffect4(() => {
676
+ inputRef.current = input;
677
+ }, [input]);
674
678
  const refetch = useCallback3(() => {
675
- execute(input);
676
- }, [execute, JSON.stringify(input)]);
677
- const refetchRef = useRef4(refetch);
679
+ execute(inputRef.current);
680
+ }, [execute]);
681
+ const previousInput = useRef4(JSON.stringify(input));
678
682
  useEffect4(() => {
679
- refetchRef.current = refetch;
680
- }, [refetch]);
683
+ const currentInputString = JSON.stringify(input);
684
+ if (previousInput.current === currentInputString) {
685
+ return;
686
+ }
687
+ if (enabled && state.called) {
688
+ console.log("[Query Changed] Input changed, refetching...");
689
+ refetch();
690
+ }
691
+ previousInput.current = currentInputString;
692
+ }, [input, enabled, state.called, refetch]);
681
693
  useEffect4(() => {
682
694
  if (enabled && actionConfig.autoFetch && !state.called && !state.loading) {
683
- refetchRef.current();
695
+ refetch();
684
696
  } else if (enabled && state.isStale && !state.loading) {
685
- refetchRef.current();
697
+ refetch();
686
698
  }
687
- }, [enabled, state.isStale, state.loading, state.called, actionConfig.autoFetch]);
699
+ }, [enabled, state.isStale, state.loading, state.called, actionConfig.autoFetch, refetch]);
688
700
  return state;
689
701
  }
690
702
  function useModuleContext() {
@@ -735,7 +747,7 @@ function useApiModule(axiosInstance, moduleConfig, options = {}) {
735
747
  body: input,
736
748
  config: options2.config
737
749
  });
738
- console.log("[API Result]", result);
750
+ console.log("[API Result execute]", result);
739
751
  if (shouldCache) {
740
752
  globalStateManager.setState(cacheKey, (prev) => ({
741
753
  ...prev,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-core-lib",
3
- "version": "12.0.18",
3
+ "version": "12.0.20",
4
4
  "description": "A flexible and powerful API client library for modern web applications.",
5
5
  "type": "module",
6
6