useCallback

A hook that provides a stable callback reference while always invoking the latest version of the provided function.

Installation

npx shadcn@latest add @craftdotui/use-callback

Usage

import { useCallbackRef } from "@/hooks/use-callback";

function MyComponent() {
  const handleClick = useCallbackRef(() => {
    console.log("Button clicked!");
  });

  return <button onClick={handleClick}>Click me</button>;
}

API Reference

useCallbackRef

A hook that provides a stable callback reference while always invoking the latest version of the provided function.

ParameterTypeDescription
callbackT | undefinedThe callback function to be referenced