ztxkui 10.0.81 → 10.0.82
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.
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useMemo, useRef } from 'react';
|
|
2
|
+
function useMemoizedFn(fn) {
|
|
3
|
+
var fnRef = useRef(fn);
|
|
4
|
+
// why not write `fnRef.current = fn`?
|
|
5
|
+
// https://github.com/alibaba/hooks/issues/728
|
|
6
|
+
fnRef.current = useMemo(function () { return fn; }, [fn]);
|
|
7
|
+
var memoizedFn = useRef();
|
|
8
|
+
if (!memoizedFn.current) {
|
|
9
|
+
memoizedFn.current = function () {
|
|
10
|
+
var args = [];
|
|
11
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
12
|
+
args[_i] = arguments[_i];
|
|
13
|
+
}
|
|
14
|
+
return fnRef.current.apply(this, args);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return memoizedFn.current;
|
|
18
|
+
}
|
|
19
|
+
export default useMemoizedFn;
|