Rehooks

useEventCallback

Returns a memoized callback that remains stable across renders.

useEventCallback

Installation

npx rehooks-cli@latest add useEventCallback

Usage

Component.tsx
import { useEventCallback } from "~/hooks/useEventCallback";
 
function Component() {
  const handleClick = useEventCallback(() => {
    console.log("Clicked!");
  });
 
  return <button onClick={handleClick}>Click me</button>;
}

API

useEventCallback

useEventCallback.ts
function useEventCallback<T extends (...args: any[]) => any>(fn: T): T;

Returns a memoized version of the provided callback.

Parameters

NameTypeDescription
fnTThe callback function that depends on external values.

Returns

NameTypeDescription
fnTA stable version of the provided callback.

On this page