UNPKG

@nex-ui/hooks

Version:

A collection of React Hooks for Nex UI components.

19 lines (16 loc) 540 B
"use client"; import { useRef, useCallback } from 'react'; /** * A custom React hook that returns a stable function reference. * This is useful to avoid unnecessary re-renders when passing functions as props. * * @param fn - The function to wrap. * @returns A stable function reference that always points to the latest version of `fn`. */ const useEvent = (fn)=>{ const latest = useRef(fn); latest.current = fn; return useCallback((...args)=>{ return latest.current(...args); }, []); }; export { useEvent };