UNPKG

@gechiui/components

Version:
28 lines (26 loc) 688 B
/** * External dependencies */ // eslint-disable-next-line no-restricted-imports /** * GeChiUI dependencies */ import { useRef } from '@gechiui/element'; import { useIsomorphicLayoutEffect } from '@gechiui/compose'; /** * Creates a reference for a prop. This is useful for preserving dependency * memoization for hooks like useCallback. * * @see https://codesandbox.io/s/uselatestref-mlj3i?file=/src/App.tsx * * @param value The value to reference * @return The prop reference. */ export function useLatestRef(value) { const ref = useRef(value); useIsomorphicLayoutEffect(() => { ref.current = value; }); return ref; } //# sourceMappingURL=use-latest-ref.js.map