@snack-uikit/utils 3.8.3-preview-69fcfa33.0 → 3.8.3-preview-92d6fde1.0

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.
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- 'use client';
3
2
 
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
@@ -6,3 +6,4 @@ export * from './useSwipeable';
6
6
  export * from './useThemeConfig';
7
7
  export * from './useValueControl';
8
8
  export * from './useDataPersist';
9
+ export * from './usePopstateSubscription';
@@ -29,4 +29,5 @@ __exportStar(require("./useIsomorphicLayoutEffect"), exports);
29
29
  __exportStar(require("./useSwipeable"), exports);
30
30
  __exportStar(require("./useThemeConfig"), exports);
31
31
  __exportStar(require("./useValueControl"), exports);
32
- __exportStar(require("./useDataPersist"), exports);
32
+ __exportStar(require("./useDataPersist"), exports);
33
+ __exportStar(require("./usePopstateSubscription"), exports);
@@ -0,0 +1 @@
1
+ export declare function usePopstateSubscription(callback: (e: PopStateEvent) => void, enabled?: boolean): void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.usePopstateSubscription = usePopstateSubscription;
7
+ const react_1 = require("react");
8
+ const useEventHandler_1 = require("./useEventHandler");
9
+ function usePopstateSubscription(callback) {
10
+ let enabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
11
+ const handler = (0, useEventHandler_1.useEventHandler)(callback);
12
+ (0, react_1.useEffect)(() => {
13
+ if (!enabled) return;
14
+ window.addEventListener('popstate', handler);
15
+ return () => window.removeEventListener('popstate', handler);
16
+ }, [enabled, handler]);
17
+ }
@@ -1,4 +1,3 @@
1
- 'use client';
2
1
  import { createContext, useContext } from 'react';
3
2
  export const ThemeContext = createContext({
4
3
  theme: undefined,
@@ -6,3 +6,4 @@ export * from './useSwipeable';
6
6
  export * from './useThemeConfig';
7
7
  export * from './useValueControl';
8
8
  export * from './useDataPersist';
9
+ export * from './usePopstateSubscription';
@@ -6,3 +6,4 @@ export * from './useSwipeable';
6
6
  export * from './useThemeConfig';
7
7
  export * from './useValueControl';
8
8
  export * from './useDataPersist';
9
+ export * from './usePopstateSubscription';
@@ -0,0 +1 @@
1
+ export declare function usePopstateSubscription(callback: (e: PopStateEvent) => void, enabled?: boolean): void;
@@ -0,0 +1,11 @@
1
+ import { useEffect } from 'react';
2
+ import { useEventHandler } from './useEventHandler';
3
+ export function usePopstateSubscription(callback, enabled = true) {
4
+ const handler = useEventHandler(callback);
5
+ useEffect(() => {
6
+ if (!enabled)
7
+ return;
8
+ window.addEventListener('popstate', handler);
9
+ return () => window.removeEventListener('popstate', handler);
10
+ }, [enabled, handler]);
11
+ }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Utils",
7
- "version": "3.8.3-preview-69fcfa33.0",
7
+ "version": "3.8.3-preview-92d6fde1.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -39,5 +39,5 @@
39
39
  "react-swipeable": "7.0.2",
40
40
  "uncontrollable": "8.0.4"
41
41
  },
42
- "gitHead": "29427722aa93f2a800d130b6ab3db58fee5901c3"
42
+ "gitHead": "b69eea8eab30c5cf2d251a9985c6310aac3192b8"
43
43
  }
@@ -1,5 +1,3 @@
1
- 'use client'
2
-
3
1
  import { createContext, useContext } from 'react';
4
2
 
5
3
  export type ThemeContextType = {
@@ -6,3 +6,4 @@ export * from './useSwipeable';
6
6
  export * from './useThemeConfig';
7
7
  export * from './useValueControl';
8
8
  export * from './useDataPersist';
9
+ export * from './usePopstateSubscription';
@@ -0,0 +1,14 @@
1
+ import { useEffect } from 'react';
2
+
3
+ import { useEventHandler } from './useEventHandler';
4
+
5
+ export function usePopstateSubscription(callback: (e: PopStateEvent) => void, enabled: boolean = true) {
6
+ const handler = useEventHandler(callback);
7
+
8
+ useEffect(() => {
9
+ if (!enabled) return;
10
+
11
+ window.addEventListener('popstate', handler);
12
+ return () => window.removeEventListener('popstate', handler);
13
+ }, [enabled, handler]);
14
+ }