@linzjs/windows 6.0.0 → 6.1.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,12 +1,18 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
|
|
3
|
+
const VoidFn = () => {
|
|
4
|
+
// empty
|
|
5
|
+
};
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* When calling external non-react components, and you can't update the function when state changes,
|
|
5
9
|
* use this to proxy the dynamic function with a static function.
|
|
6
10
|
*/
|
|
7
|
-
export const useConstFunction = <Args extends never[], R, TFn extends (...args: Args) => R
|
|
11
|
+
export const useConstFunction = <Args extends never[], R, TFn extends ((...args: Args) => R) | null | undefined>(
|
|
12
|
+
fn: TFn = VoidFn as TFn,
|
|
13
|
+
): TFn => {
|
|
8
14
|
const functionRef = useRef<TFn>(fn);
|
|
9
|
-
const proxyRef = useRef<TFn>(((...args: Args) => functionRef.current(...args)) as TFn);
|
|
15
|
+
const proxyRef = useRef<TFn>(((...args: Args) => functionRef.current?.(...args)) as TFn);
|
|
10
16
|
|
|
11
17
|
useEffect(() => {
|
|
12
18
|
functionRef.current = fn;
|