We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 10c5697 commit 1d3dddaCopy full SHA for 1d3ddda
src/hooks/useEvent.ts
@@ -2,12 +2,14 @@
2
/* eslint-disable react-hooks/exhaustive-deps */
3
import * as React from 'react';
4
5
-function useEvent<T extends Function>(callback: T): T {
6
- const fnRef = React.useRef<any>();
+function useEvent<T extends (...args: any[]) => any>(
+ callback: T | undefined,
7
+): T {
8
+ const fnRef = React.useRef<T | undefined>(callback);
9
fnRef.current = callback;
10
- const memoFn = React.useCallback<T>(
- ((...args: any) => fnRef.current?.(...args)) as any,
11
+ const memoFn = React.useCallback(
12
+ ((...args) => fnRef.current?.(...args)) as T,
13
[],
14
);
15
0 commit comments