UNPKG

@arolariu/components

Version:

🎨 70+ beautiful, accessible React components built on Base UI. TypeScript-first, CSS Modules styling, tree-shakeable, SSR-ready. Perfect for modern web apps, design systems & rapid prototyping. Zero config, maximum flexibility! ⚡

34 lines • 1.52 kB
/** * Creates a stable callback reference that always calls the latest version of the provided function. * * @remarks * Unlike `useCallback`, this hook returns a stable function reference that never changes, * but always invokes the most recent version of the callback. This is useful when you need * to pass callbacks to optimized child components or effects without triggering re-renders * when dependencies change. * * The returned function is safe to use in dependency arrays because its identity never changes. * * @typeParam Args - The tuple type of the callback's arguments. * @typeParam Return - The return type of the callback. * @param callback - The function to wrap with a stable reference. * @returns A stable function reference that invokes the latest callback. * * @example * ```tsx * function SearchInput({onSearch}) { * const [query, setQuery] = useState(""); * // stableOnSearch never changes identity, but always calls the latest onSearch * const stableOnSearch = useEventCallback(onSearch); * * useEffect(() => { * const timer = setTimeout(() => stableOnSearch(query), 500); * return () => clearTimeout(timer); * }, [query, stableOnSearch]); // Safe to include in deps * * return <input value={query} onChange={(e) => setQuery(e.target.value)} />; * } * ``` */ export declare function useEventCallback<Args extends unknown[], Return>(callback: (...args: Args) => Return): (...args: Args) => Return; //# sourceMappingURL=useEventCallback.d.ts.map