/** * useEventCallback Hook * * Creates a stable callback reference that always calls the latest version * of the callback. Useful for event handlers passed to child components * or used in effects where you don't want to recreate the callback on * every render but need access to fresh values. * * @since v1.35.0 */ /** * Creates a stable event callback that always calls the latest callback version * * The returned function maintains a stable reference across renders, * but always executes the most recent version of the callback. * This is useful for: * - Event handlers passed to memoized children * - Callbacks used in useEffect without causing re-runs * - Breaking circular dependency issues in hooks * * @param callback - The callback function * @returns A stable callback that always calls the latest version * * @example * ```typescript * function SearchComponent({ onSearch }) { * const [query, setQuery] = useState(''); * * // This callback is stable but always has access to latest query * const handleSearch = useEventCallback(() => { * onSearch(query); * }); * * // Can safely pass to memoized children without causing re-renders * return ( * * Search * * ); * } * ``` * * @example * ```typescript * // Use in effects without adding to dependency array * const handleResize = useEventCallback(() => { * console.log('Window size:', window.innerWidth); * updateLayout(currentConfig); // Always has latest config * }); * * useEffect(() => { * window.addEventListener('resize', handleResize); * return () => window.removeEventListener('resize', handleResize); * }, [handleResize]); // handleResize is stable, effect doesn't re-run * ``` */ export declare function useEventCallback unknown>(callback: T): T; /** * Creates a stable callback that can be called with any arguments * Similar to useEventCallback but with explicit argument typing * * @param callback - The callback function * @returns A stable callback wrapper * * @example * ```typescript * const handleChange = useStableCallback((value: string) => { * console.log('Changed to:', value); * updateState(value); * }); * ``` */ export declare function useStableCallback(callback: (...args: Args) => R): (...args: Args) => R; /** * Creates a stable ref getter function * Returns a function that always gets the latest value of a ref * * @param value - The value to track * @returns A stable getter function * * @example * ```typescript * const [count, setCount] = useState(0); * const getCount = useLatestValue(count); * * useEffect(() => { * const interval = setInterval(() => { * console.log('Current count:', getCount()); * }, 1000); * return () => clearInterval(interval); * }, []); // No need to include count in deps * ``` */ export declare function useLatestValue(value: T): () => T; //# sourceMappingURL=useEventCallback.d.ts.map