Rehooks
Hooks

useEventCallback

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

useEventCallback

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

Usage

import { useEventCallback } from "rehooks-ts";
 
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