UNPKG

react-modal-sheet

Version:

Flexible bottom sheet component for your React apps

19 lines (14 loc) 452 B
import { useCallback, useRef } from 'react'; import { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect'; export function useStableCallback<T extends (...args: any[]) => any>( handler: T ) { const handlerRef = useRef<T>(undefined); useIsomorphicLayoutEffect(() => { handlerRef.current = handler; }); return useCallback((...args: any[]) => { const fn = handlerRef.current; return fn?.(...args); }, []) as T; }