@nguyentc21/react-native-tooltip
Version:
Simple tooltip for React native app
14 lines (10 loc) • 381 B
text/typescript
import { useRef, useCallback } from 'react';
type Cb = (...a: any[]) => any;
function useStableCallback<T extends Cb | null | undefined>(
fn: T
): T extends Cb ? (...args: Parameters<T>) => ReturnType<T> : () => void {
const ref = useRef(fn);
ref.current = fn;
return useCallback<any>((...args: any[]) => ref.current?.(...args), []);
}
export default useStableCallback;