@spoosh/react 0.15.3 → 0.15.4

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
@@ -688,6 +688,7 @@ function createUseSubscription(options) {
688
688
  });
689
689
  const controllerRef = (0, import_react5.useRef)(null);
690
690
  const subscriptionVersionRef = (0, import_react5.useRef)(0);
691
+ const prevQueryKeyRef = (0, import_react5.useRef)(queryKey);
691
692
  const queryKeyChanged = controllerRef.current && controllerRef.current.queryKey !== queryKey;
692
693
  if (!controllerRef.current || queryKeyChanged) {
693
694
  const controller2 = (0, import_core5.createSubscriptionController)({
@@ -716,14 +717,18 @@ function createUseSubscription(options) {
716
717
  const state = (0, import_react5.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
717
718
  const [isPending, setIsPending] = (0, import_react5.useState)(enabled);
718
719
  (0, import_react5.useEffect)(() => {
720
+ const queryKeyChanged2 = prevQueryKeyRef.current !== queryKey;
721
+ prevQueryKeyRef.current = queryKey;
719
722
  if (!enabled) {
720
723
  return;
721
724
  }
725
+ if (queryKeyChanged2) {
726
+ subscriptionVersionRef.current++;
727
+ }
722
728
  setIsPending(true);
723
729
  controller.mount();
724
730
  controller.subscribe();
725
731
  return () => {
726
- subscriptionVersionRef.current++;
727
732
  controller.unsubscribe();
728
733
  };
729
734
  }, [queryKey, enabled, controller]);
@@ -733,7 +738,6 @@ function createUseSubscription(options) {
733
738
  }
734
739
  }, [state.isConnected, state.data, state.error]);
735
740
  const disconnect = (0, import_react5.useCallback)(() => {
736
- subscriptionVersionRef.current++;
737
741
  controller.unsubscribe();
738
742
  }, [controller]);
739
743
  const trigger = (0, import_react5.useCallback)(async () => {
package/dist/index.mjs CHANGED
@@ -712,6 +712,7 @@ function createUseSubscription(options) {
712
712
  });
713
713
  const controllerRef = useRef5(null);
714
714
  const subscriptionVersionRef = useRef5(0);
715
+ const prevQueryKeyRef = useRef5(queryKey);
715
716
  const queryKeyChanged = controllerRef.current && controllerRef.current.queryKey !== queryKey;
716
717
  if (!controllerRef.current || queryKeyChanged) {
717
718
  const controller2 = createSubscriptionController({
@@ -740,14 +741,18 @@ function createUseSubscription(options) {
740
741
  const state = useSyncExternalStore5(subscribe, getSnapshot, getSnapshot);
741
742
  const [isPending, setIsPending] = useState4(enabled);
742
743
  useEffect4(() => {
744
+ const queryKeyChanged2 = prevQueryKeyRef.current !== queryKey;
745
+ prevQueryKeyRef.current = queryKey;
743
746
  if (!enabled) {
744
747
  return;
745
748
  }
749
+ if (queryKeyChanged2) {
750
+ subscriptionVersionRef.current++;
751
+ }
746
752
  setIsPending(true);
747
753
  controller.mount();
748
754
  controller.subscribe();
749
755
  return () => {
750
- subscriptionVersionRef.current++;
751
756
  controller.unsubscribe();
752
757
  };
753
758
  }, [queryKey, enabled, controller]);
@@ -757,7 +762,6 @@ function createUseSubscription(options) {
757
762
  }
758
763
  }, [state.isConnected, state.data, state.error]);
759
764
  const disconnect = useCallback4(() => {
760
- subscriptionVersionRef.current++;
761
765
  controller.unsubscribe();
762
766
  }, [controller]);
763
767
  const trigger = useCallback4(async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spoosh/react",
3
- "version": "0.15.3",
3
+ "version": "0.15.4",
4
4
  "license": "MIT",
5
5
  "description": "React hooks for Spoosh API toolkit",
6
6
  "keywords": [