UNPKG

@nex-ui/hooks

Version:

A collection of React Hooks for Nex UI components.

22 lines (19 loc) 491 B
"use client"; import { useRef } from 'react'; /** * A custom hook that returns a ref to the latest value. * This is useful to avoid stale closures in event handlers or effects. * * @param value - The value to keep track of. * @returns A ref object containing the latest value. * * @example * ```tsx * const latestValue = useLatest(someValue); * ``` */ const useLatest = (value)=>{ const ref = useRef(value); ref.current = value; return ref; }; export { useLatest };