Rehooks
Content

useEventCallback

A hook that returns a memoized version of a callback that is stable between renders.

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

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