@pushwoosh/kit-helpers 4.12.5 → 4.12.6
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.
|
@@ -44,4 +44,4 @@
|
|
|
44
44
|
* return <div>...</div>;
|
|
45
45
|
* };
|
|
46
46
|
*/
|
|
47
|
-
export default function usePersistentFunction<Args extends
|
|
47
|
+
export default function usePersistentFunction<Args extends unknown[], Return>(callback: (...args: Args) => Return): (...args: Args) => Return;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useInsertionEffect, useRef } from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* Creates a stable function reference that always calls the latest version of a callback.
|
|
4
4
|
*
|
|
@@ -46,10 +46,17 @@ import { useCallback, useRef } from 'react';
|
|
|
46
46
|
* };
|
|
47
47
|
*/
|
|
48
48
|
export default function usePersistentFunction(callback) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
const holderRef = useRef(null);
|
|
50
|
+
if (holderRef.current === null) {
|
|
51
|
+
const created = {
|
|
52
|
+
latest: callback,
|
|
53
|
+
fn: (...args) => created.latest(...args)
|
|
54
|
+
};
|
|
55
|
+
holderRef.current = created;
|
|
56
|
+
}
|
|
57
|
+
const holder = holderRef.current;
|
|
58
|
+
useInsertionEffect(() => {
|
|
59
|
+
holder.latest = callback;
|
|
60
|
+
});
|
|
61
|
+
return holder.fn;
|
|
55
62
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushwoosh/kit-helpers",
|
|
3
|
-
"version": "4.12.
|
|
3
|
+
"version": "4.12.6",
|
|
4
4
|
"description": "React component for build Pushwoosh products",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"react-transition-group": "^4.4.5"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@pushwoosh/kit-constants": "^1.
|
|
17
|
+
"@pushwoosh/kit-constants": "^2.1.0",
|
|
18
18
|
"@types/react": "^18.3.31",
|
|
19
19
|
"@types/react-dom": "^18.3.7",
|
|
20
20
|
"@types/react-transition-group": "^4.4.10",
|