react-simplikit 0.0.47 → 0.0.49

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.
Files changed (57) hide show
  1. package/dist/components/ImpressionArea/index.cjs +7 -4
  2. package/dist/components/Separated/index.cjs +1 -1
  3. package/dist/hooks/useCallbackOncePerRender/index.cjs +6 -3
  4. package/dist/hooks/useDebounce/index.cjs +14 -8
  5. package/dist/hooks/useDebouncedCallback/index.cjs +7 -4
  6. package/dist/hooks/useDoubleClick/index.cjs +6 -3
  7. package/dist/hooks/useImpressionRef/index.cjs +7 -4
  8. package/dist/hooks/useIntersectionObserver/index.cjs +6 -3
  9. package/dist/hooks/useInterval/index.cjs +24 -15
  10. package/dist/hooks/useIsClient/index.cjs +40 -0
  11. package/dist/hooks/useIsClient/index.d.cts +40 -0
  12. package/dist/hooks/useList/index.cjs +104 -0
  13. package/dist/hooks/useList/index.d.cts +50 -0
  14. package/dist/hooks/useLoading/index.cjs +9 -6
  15. package/dist/hooks/useLongPress/index.cjs +6 -3
  16. package/dist/hooks/useOutsideClickEffect/index.cjs +6 -3
  17. package/dist/hooks/usePreservedCallback/index.cjs +6 -3
  18. package/dist/hooks/useRefEffect/index.cjs +6 -3
  19. package/dist/hooks/useRefEffect/index.d.cts +3 -3
  20. package/dist/hooks/useSet/index.cjs +105 -0
  21. package/dist/hooks/useSet/index.d.cts +39 -0
  22. package/dist/hooks/useThrottle/index.cjs +6 -3
  23. package/dist/hooks/useThrottledCallback/index.cjs +172 -0
  24. package/dist/hooks/useThrottledCallback/index.d.cts +30 -0
  25. package/dist/hooks/useTimeout/index.cjs +8 -5
  26. package/dist/hooks/useTimeout/index.d.cts +1 -1
  27. package/dist/index.cjs +252 -96
  28. package/dist/index.d.cts +4 -0
  29. package/esm/components/ImpressionArea/index.js +7 -4
  30. package/esm/components/Separated/index.js +1 -1
  31. package/esm/hooks/useCallbackOncePerRender/index.js +6 -3
  32. package/esm/hooks/useDebounce/index.js +14 -8
  33. package/esm/hooks/useDebouncedCallback/index.js +7 -4
  34. package/esm/hooks/useDoubleClick/index.js +6 -3
  35. package/esm/hooks/useImpressionRef/index.js +7 -4
  36. package/esm/hooks/useIntersectionObserver/index.js +6 -3
  37. package/esm/hooks/useInterval/index.js +24 -15
  38. package/esm/hooks/useIsClient/index.d.ts +40 -0
  39. package/esm/hooks/useIsClient/index.js +14 -0
  40. package/esm/hooks/useList/index.d.ts +50 -0
  41. package/esm/hooks/useList/index.js +78 -0
  42. package/esm/hooks/useLoading/index.js +9 -6
  43. package/esm/hooks/useLongPress/index.js +6 -3
  44. package/esm/hooks/useOutsideClickEffect/index.js +6 -3
  45. package/esm/hooks/usePreservedCallback/index.js +6 -3
  46. package/esm/hooks/useRefEffect/index.d.ts +3 -3
  47. package/esm/hooks/useRefEffect/index.js +6 -3
  48. package/esm/hooks/useSet/index.d.ts +39 -0
  49. package/esm/hooks/useSet/index.js +79 -0
  50. package/esm/hooks/useThrottle/index.js +6 -3
  51. package/esm/hooks/useThrottledCallback/index.d.ts +30 -0
  52. package/esm/hooks/useThrottledCallback/index.js +146 -0
  53. package/esm/hooks/useTimeout/index.d.ts +1 -1
  54. package/esm/hooks/useTimeout/index.js +8 -5
  55. package/esm/index.d.ts +4 -0
  56. package/esm/index.js +222 -70
  57. package/package.json +18 -19
@@ -91,9 +91,12 @@ function debounce(func, debounceMs, { edges = ["leading", "trailing"] } = {}) {
91
91
  var import_react = require("react");
92
92
  function usePreservedCallback(callback) {
93
93
  const callbackRef = (0, import_react.useRef)(callback);
94
- (0, import_react.useEffect)(() => {
95
- callbackRef.current = callback;
96
- }, [callback]);
94
+ (0, import_react.useEffect)(
95
+ function syncCallbackRef() {
96
+ callbackRef.current = callback;
97
+ },
98
+ [callback]
99
+ );
97
100
  return (0, import_react.useCallback)((...args) => {
98
101
  return callbackRef.current(...args);
99
102
  }, []);
@@ -109,7 +112,7 @@ function useDebouncedCallback({
109
112
  const handleChange = usePreservedCallback(onChange);
110
113
  const ref = (0, import_react2.useRef)({ value: false, clearPreviousDebounce: () => {
111
114
  } });
112
- (0, import_react2.useEffect)(() => {
115
+ (0, import_react2.useEffect)(function clearDebouncedOnUnmount() {
113
116
  const current = ref.current;
114
117
  return () => {
115
118
  current.clearPreviousDebounce();
@@ -33,7 +33,7 @@ function Separated({ children, by: separator }) {
33
33
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: childrenArray.map((child, i, { length }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [
34
34
  child,
35
35
  i + 1 !== length && separator
36
- ] }, i)) });
36
+ ] }, child.key ?? i)) });
37
37
  }
38
38
  // Annotate the CommonJS export names for ESM import in node:
39
39
  0 && (module.exports = {
@@ -32,9 +32,12 @@ var import_react2 = require("react");
32
32
  var import_react = require("react");
33
33
  function usePreservedCallback(callback) {
34
34
  const callbackRef = (0, import_react.useRef)(callback);
35
- (0, import_react.useEffect)(() => {
36
- callbackRef.current = callback;
37
- }, [callback]);
35
+ (0, import_react.useEffect)(
36
+ function syncCallbackRef() {
37
+ callbackRef.current = callback;
38
+ },
39
+ [callback]
40
+ );
38
41
  return (0, import_react.useCallback)((...args) => {
39
42
  return callbackRef.current(...args);
40
43
  }, []);
@@ -33,9 +33,12 @@ var import_react3 = require("react");
33
33
  var import_react = require("react");
34
34
  function usePreservedCallback(callback) {
35
35
  const callbackRef = (0, import_react.useRef)(callback);
36
- (0, import_react.useEffect)(() => {
37
- callbackRef.current = callback;
38
- }, [callback]);
36
+ (0, import_react.useEffect)(
37
+ function syncCallbackRef() {
38
+ callbackRef.current = callback;
39
+ },
40
+ [callback]
41
+ );
39
42
  return (0, import_react.useCallback)((...args) => {
40
43
  return callbackRef.current(...args);
41
44
  }, []);
@@ -111,11 +114,14 @@ function useDebounce(callback, wait, options = {}) {
111
114
  const debounced = (0, import_react3.useMemo)(() => {
112
115
  return debounce(preservedCallback, wait, { edges });
113
116
  }, [preservedCallback, wait, edges]);
114
- (0, import_react2.useEffect)(() => {
115
- return () => {
116
- debounced.cancel();
117
- };
118
- }, [debounced]);
117
+ (0, import_react2.useEffect)(
118
+ function cancelDebouncedOnUnmount() {
119
+ return () => {
120
+ debounced.cancel();
121
+ };
122
+ },
123
+ [debounced]
124
+ );
119
125
  return debounced;
120
126
  }
121
127
  // Annotate the CommonJS export names for ESM import in node:
@@ -85,9 +85,12 @@ function debounce(func, debounceMs, { edges = ["leading", "trailing"] } = {}) {
85
85
  var import_react = require("react");
86
86
  function usePreservedCallback(callback) {
87
87
  const callbackRef = (0, import_react.useRef)(callback);
88
- (0, import_react.useEffect)(() => {
89
- callbackRef.current = callback;
90
- }, [callback]);
88
+ (0, import_react.useEffect)(
89
+ function syncCallbackRef() {
90
+ callbackRef.current = callback;
91
+ },
92
+ [callback]
93
+ );
91
94
  return (0, import_react.useCallback)((...args) => {
92
95
  return callbackRef.current(...args);
93
96
  }, []);
@@ -103,7 +106,7 @@ function useDebouncedCallback({
103
106
  const handleChange = usePreservedCallback(onChange);
104
107
  const ref = (0, import_react2.useRef)({ value: false, clearPreviousDebounce: () => {
105
108
  } });
106
- (0, import_react2.useEffect)(() => {
109
+ (0, import_react2.useEffect)(function clearDebouncedOnUnmount() {
107
110
  const current = ref.current;
108
111
  return () => {
109
112
  current.clearPreviousDebounce();
@@ -32,9 +32,12 @@ var import_react2 = require("react");
32
32
  var import_react = require("react");
33
33
  function usePreservedCallback(callback) {
34
34
  const callbackRef = (0, import_react.useRef)(callback);
35
- (0, import_react.useEffect)(() => {
36
- callbackRef.current = callback;
37
- }, [callback]);
35
+ (0, import_react.useEffect)(
36
+ function syncCallbackRef() {
37
+ callbackRef.current = callback;
38
+ },
39
+ [callback]
40
+ );
38
41
  return (0, import_react.useCallback)((...args) => {
39
42
  return callbackRef.current(...args);
40
43
  }, []);
@@ -88,9 +88,12 @@ function debounce(func, debounceMs, { edges = ["leading", "trailing"] } = {}) {
88
88
  var import_react = require("react");
89
89
  function usePreservedCallback(callback) {
90
90
  const callbackRef = (0, import_react.useRef)(callback);
91
- (0, import_react.useEffect)(() => {
92
- callbackRef.current = callback;
93
- }, [callback]);
91
+ (0, import_react.useEffect)(
92
+ function syncCallbackRef() {
93
+ callbackRef.current = callback;
94
+ },
95
+ [callback]
96
+ );
94
97
  return (0, import_react.useCallback)((...args) => {
95
98
  return callbackRef.current(...args);
96
99
  }, []);
@@ -106,7 +109,7 @@ function useDebouncedCallback({
106
109
  const handleChange = usePreservedCallback(onChange);
107
110
  const ref = (0, import_react2.useRef)({ value: false, clearPreviousDebounce: () => {
108
111
  } });
109
- (0, import_react2.useEffect)(() => {
112
+ (0, import_react2.useEffect)(function clearDebouncedOnUnmount() {
110
113
  const current = ref.current;
111
114
  return () => {
112
115
  current.clearPreviousDebounce();
@@ -32,9 +32,12 @@ var import_react3 = require("react");
32
32
  var import_react = require("react");
33
33
  function usePreservedCallback(callback) {
34
34
  const callbackRef = (0, import_react.useRef)(callback);
35
- (0, import_react.useEffect)(() => {
36
- callbackRef.current = callback;
37
- }, [callback]);
35
+ (0, import_react.useEffect)(
36
+ function syncCallbackRef() {
37
+ callbackRef.current = callback;
38
+ },
39
+ [callback]
40
+ );
38
41
  return (0, import_react.useCallback)((...args) => {
39
42
  return callbackRef.current(...args);
40
43
  }, []);
@@ -32,9 +32,12 @@ var import_react2 = require("react");
32
32
  var import_react = require("react");
33
33
  function usePreservedCallback(callback) {
34
34
  const callbackRef = (0, import_react.useRef)(callback);
35
- (0, import_react.useEffect)(() => {
36
- callbackRef.current = callback;
37
- }, [callback]);
35
+ (0, import_react.useEffect)(
36
+ function syncCallbackRef() {
37
+ callbackRef.current = callback;
38
+ },
39
+ [callback]
40
+ );
38
41
  return (0, import_react.useCallback)((...args) => {
39
42
  return callbackRef.current(...args);
40
43
  }, []);
@@ -46,18 +49,24 @@ function useInterval(callback, options) {
46
49
  const immediate = typeof options === "number" ? false : options.immediate;
47
50
  const enabled = typeof options === "number" ? true : options.enabled ?? true;
48
51
  const preservedCallback = usePreservedCallback(callback);
49
- (0, import_react2.useEffect)(() => {
50
- if (immediate === true && enabled) {
51
- preservedCallback();
52
- }
53
- }, [immediate, preservedCallback, enabled]);
54
- (0, import_react2.useEffect)(() => {
55
- if (!enabled) {
56
- return;
57
- }
58
- const id = window.setInterval(preservedCallback, delay);
59
- return () => window.clearInterval(id);
60
- }, [delay, preservedCallback, enabled]);
52
+ (0, import_react2.useEffect)(
53
+ function runImmediateCallback() {
54
+ if (immediate === true && enabled) {
55
+ preservedCallback();
56
+ }
57
+ },
58
+ [immediate, preservedCallback, enabled]
59
+ );
60
+ (0, import_react2.useEffect)(
61
+ function startInterval() {
62
+ if (!enabled) {
63
+ return;
64
+ }
65
+ const id = setInterval(preservedCallback, delay);
66
+ return () => clearInterval(id);
67
+ },
68
+ [delay, preservedCallback, enabled]
69
+ );
61
70
  }
62
71
  // Annotate the CommonJS export names for ESM import in node:
63
72
  0 && (module.exports = {
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/hooks/useIsClient/index.ts
22
+ var useIsClient_exports = {};
23
+ __export(useIsClient_exports, {
24
+ useIsClient: () => useIsClient
25
+ });
26
+ module.exports = __toCommonJS(useIsClient_exports);
27
+
28
+ // src/hooks/useIsClient/useIsClient.ts
29
+ var import_react = require("react");
30
+ function useIsClient() {
31
+ const [isClient, setIsClient] = (0, import_react.useState)(false);
32
+ (0, import_react.useEffect)(function syncClientState() {
33
+ setIsClient(true);
34
+ }, []);
35
+ return isClient;
36
+ }
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ useIsClient
40
+ });
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @description
3
+ * `useIsClient` is a React hook that returns `true` only in the client-side environment.
4
+ * It is primarily used to differentiate between client-side and server-side rendering (SSR).
5
+ * The state is set to `true` only after the component is mounted in the client-side environment.
6
+ *
7
+ * @returns {boolean} Returns `true` in a client-side environment, and `false` otherwise.
8
+ *
9
+ * @example
10
+ * function ClientSideContent() {
11
+ * const isClient = useIsClient();
12
+ *
13
+ * if (!isClient) {
14
+ * return <div>Loading...</div>; // Rendered on the server side
15
+ * }
16
+ *
17
+ * return <div>Client-side rendered content</div>; // Rendered on the client side
18
+ * }
19
+ *
20
+ * @example
21
+ * function ClientOnlyMap() {
22
+ * const isClient = useIsClient();
23
+ *
24
+ * if (!isClient) return null;
25
+ *
26
+ * return <div id="map" />;
27
+ * }
28
+ *
29
+ * @example
30
+ * function ClientTheme() {
31
+ * const isClient = useIsClient();
32
+ *
33
+ * const theme = isClient ? localStorage.getItem('theme') : 'light';
34
+ *
35
+ * return <div>Current theme: {theme}</div>;
36
+ * }
37
+ */
38
+ declare function useIsClient(): boolean;
39
+
40
+ export { useIsClient };
@@ -0,0 +1,104 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/hooks/useList/index.ts
22
+ var useList_exports = {};
23
+ __export(useList_exports, {
24
+ useList: () => useList
25
+ });
26
+ module.exports = __toCommonJS(useList_exports);
27
+
28
+ // src/hooks/useList/useList.ts
29
+ var import_react3 = require("react");
30
+
31
+ // src/hooks/usePreservedCallback/usePreservedCallback.ts
32
+ var import_react = require("react");
33
+ function usePreservedCallback(callback) {
34
+ const callbackRef = (0, import_react.useRef)(callback);
35
+ (0, import_react.useEffect)(
36
+ function syncCallbackRef() {
37
+ callbackRef.current = callback;
38
+ },
39
+ [callback]
40
+ );
41
+ return (0, import_react.useCallback)((...args) => {
42
+ return callbackRef.current(...args);
43
+ }, []);
44
+ }
45
+
46
+ // src/hooks/usePreservedReference/usePreservedReference.ts
47
+ var import_react2 = require("react");
48
+ function usePreservedReference(value, areValuesEqual = areDeeplyEqual) {
49
+ const ref = (0, import_react2.useRef)(value);
50
+ return (0, import_react2.useMemo)(() => {
51
+ if (!areValuesEqual(ref.current, value)) {
52
+ ref.current = value;
53
+ }
54
+ return ref.current;
55
+ }, [areValuesEqual, value]);
56
+ }
57
+ function areDeeplyEqual(x, y) {
58
+ return JSON.stringify(x) === JSON.stringify(y);
59
+ }
60
+
61
+ // src/hooks/useList/useList.ts
62
+ function useList(initialState = []) {
63
+ const [list, setList] = (0, import_react3.useState)(initialState);
64
+ const preservedInitialState = usePreservedReference(initialState);
65
+ const push = usePreservedCallback((value) => {
66
+ setList((prev) => [...prev, value]);
67
+ });
68
+ const insertAt = usePreservedCallback((index, value) => {
69
+ setList((prev) => {
70
+ const next = [...prev];
71
+ next.splice(index, 0, value);
72
+ return next;
73
+ });
74
+ });
75
+ const updateAt = usePreservedCallback((index, value) => {
76
+ setList((prev) => {
77
+ const next = [...prev];
78
+ next[index] = value;
79
+ return next;
80
+ });
81
+ });
82
+ const removeAt = usePreservedCallback((index) => {
83
+ setList((prev) => {
84
+ const next = [...prev];
85
+ next.splice(index, 1);
86
+ return next;
87
+ });
88
+ });
89
+ const setAll = usePreservedCallback((values) => {
90
+ setList(values);
91
+ });
92
+ const reset = usePreservedCallback(() => {
93
+ setList(preservedInitialState);
94
+ });
95
+ const actions = (0, import_react3.useMemo)(
96
+ () => ({ push, insertAt, updateAt, removeAt, setAll, reset }),
97
+ [push, insertAt, updateAt, removeAt, setAll, reset]
98
+ );
99
+ return [list, actions];
100
+ }
101
+ // Annotate the CommonJS export names for ESM import in node:
102
+ 0 && (module.exports = {
103
+ useList
104
+ });
@@ -0,0 +1,50 @@
1
+ type ListActions<T> = {
2
+ push: (value: T) => void;
3
+ insertAt: (index: number, value: T) => void;
4
+ updateAt: (index: number, value: T) => void;
5
+ removeAt: (index: number) => void;
6
+ setAll: (values: T[]) => void;
7
+ reset: () => void;
8
+ };
9
+ type UseListReturn<T> = [ReadonlyArray<T>, ListActions<T>];
10
+ /**
11
+ * @description
12
+ * A React hook that manages an array as state.
13
+ * Provides efficient state management and stable action functions.
14
+ *
15
+ * @param {T[]} initialState - Initial array state
16
+ *
17
+ * @returns {UseListReturn<T>} A tuple containing the array state and actions to manipulate it
18
+ * - `push` - Appends a value to the end of the list
19
+ * - `insertAt` - Inserts a value at the specified index
20
+ * - `updateAt` - Updates the value at the specified index
21
+ * - `removeAt` - Removes the value at the specified index
22
+ * - `setAll` - Replaces the entire list with a new array
23
+ * - `reset` - Resets the list to its initial state
24
+ *
25
+ * @example
26
+ * ```tsx
27
+ * const [list, actions] = useList<string>(['apple', 'banana']);
28
+ *
29
+ * // Add an item
30
+ * actions.push('cherry');
31
+ *
32
+ * // Insert at index
33
+ * actions.insertAt(1, 'grape');
34
+ *
35
+ * // Update at index
36
+ * actions.updateAt(0, 'orange');
37
+ *
38
+ * // Remove at index
39
+ * actions.removeAt(2);
40
+ *
41
+ * // Replace all
42
+ * actions.setAll(['kiwi', 'mango']);
43
+ *
44
+ * // Reset to initial state
45
+ * actions.reset();
46
+ * ```
47
+ */
48
+ declare function useList<T>(initialState?: T[]): UseListReturn<T>;
49
+
50
+ export { useList };
@@ -48,12 +48,15 @@ function useLoading() {
48
48
  }
49
49
  function useIsMountedRef() {
50
50
  const ref = (0, import_react.useRef)({ isMounted: true }).current;
51
- (0, import_react.useEffect)(() => {
52
- ref.isMounted = true;
53
- return () => {
54
- ref.isMounted = false;
55
- };
56
- }, [ref]);
51
+ (0, import_react.useEffect)(
52
+ function trackMountedState() {
53
+ ref.isMounted = true;
54
+ return () => {
55
+ ref.isMounted = false;
56
+ };
57
+ },
58
+ [ref]
59
+ );
57
60
  return ref;
58
61
  }
59
62
  // Annotate the CommonJS export names for ESM import in node:
@@ -32,9 +32,12 @@ var import_react2 = require("react");
32
32
  var import_react = require("react");
33
33
  function usePreservedCallback(callback) {
34
34
  const callbackRef = (0, import_react.useRef)(callback);
35
- (0, import_react.useEffect)(() => {
36
- callbackRef.current = callback;
37
- }, [callback]);
35
+ (0, import_react.useEffect)(
36
+ function syncCallbackRef() {
37
+ callbackRef.current = callback;
38
+ },
39
+ [callback]
40
+ );
38
41
  return (0, import_react.useCallback)((...args) => {
39
42
  return callbackRef.current(...args);
40
43
  }, []);
@@ -32,9 +32,12 @@ var import_react2 = require("react");
32
32
  var import_react = require("react");
33
33
  function usePreservedCallback(callback) {
34
34
  const callbackRef = (0, import_react.useRef)(callback);
35
- (0, import_react.useEffect)(() => {
36
- callbackRef.current = callback;
37
- }, [callback]);
35
+ (0, import_react.useEffect)(
36
+ function syncCallbackRef() {
37
+ callbackRef.current = callback;
38
+ },
39
+ [callback]
40
+ );
38
41
  return (0, import_react.useCallback)((...args) => {
39
42
  return callbackRef.current(...args);
40
43
  }, []);
@@ -29,9 +29,12 @@ module.exports = __toCommonJS(usePreservedCallback_exports);
29
29
  var import_react = require("react");
30
30
  function usePreservedCallback(callback) {
31
31
  const callbackRef = (0, import_react.useRef)(callback);
32
- (0, import_react.useEffect)(() => {
33
- callbackRef.current = callback;
34
- }, [callback]);
32
+ (0, import_react.useEffect)(
33
+ function syncCallbackRef() {
34
+ callbackRef.current = callback;
35
+ },
36
+ [callback]
37
+ );
35
38
  return (0, import_react.useCallback)((...args) => {
36
39
  return callbackRef.current(...args);
37
40
  }, []);
@@ -32,9 +32,12 @@ var import_react2 = require("react");
32
32
  var import_react = require("react");
33
33
  function usePreservedCallback(callback) {
34
34
  const callbackRef = (0, import_react.useRef)(callback);
35
- (0, import_react.useEffect)(() => {
36
- callbackRef.current = callback;
37
- }, [callback]);
35
+ (0, import_react.useEffect)(
36
+ function syncCallbackRef() {
37
+ callbackRef.current = callback;
38
+ },
39
+ [callback]
40
+ );
38
41
  return (0, import_react.useCallback)((...args) => {
39
42
  return callbackRef.current(...args);
40
43
  }, []);
@@ -6,10 +6,10 @@ type CleanupCallback = () => void;
6
6
  * `useRefEffect` is a React hook that helps you set a reference to a specific DOM element and execute a callback whenever the element changes.
7
7
  * This hook calls a cleanup function whenever the element changes to prevent memory leaks.
8
8
  *
9
- * @param {(element: Element) => CleanupCallback | void} callback - A callback function that is executed when the element is set. This function can return a cleanup function.
9
+ * @param {(element: RefElement) => CleanupCallback | void} callback - A callback function that is executed when the element is set. This function can return a cleanup function.
10
10
  * @param {DependencyList} deps - An array of dependencies that define when the callback should be re-executed. The `callback` is re-executed whenever the `deps` change.
11
11
  *
12
- * @returns {(element: Element | null) => void} A function to set the element. Pass this function to the `ref` attribute, and the `callback` will be called whenever the element changes.
12
+ * @returns {(element: RefElement | null) => void} A function to set the element. Pass this function to the `ref` attribute, and the `callback` will be called whenever the element changes.
13
13
  *
14
14
  * @example
15
15
  * import { useRefEffect } from 'react-simplikit';
@@ -26,6 +26,6 @@ type CleanupCallback = () => void;
26
26
  * return <div ref={ref}>Basic Example</div>;
27
27
  * }
28
28
  */
29
- declare function useRefEffect<Element extends HTMLElement = HTMLElement>(callback: (element: Element) => CleanupCallback | void, deps: DependencyList): (element: Element | null) => void;
29
+ declare function useRefEffect<RefElement extends HTMLElement = HTMLElement>(callback: (element: RefElement) => CleanupCallback | void, deps: DependencyList): (element: RefElement | null) => void;
30
30
 
31
31
  export { useRefEffect };