Docs
useCallbackRef

Automatically resize a textarea to fit its content with useAutosizeTextarea.

Loading...

Installation

pnpm dlx shadcn@latest add https://usekit.kiron.dev/k/use-callback-ref

Usage

"use client"
 
import * as React from "react"
 
import { useCallbackRef } from "@/hooks/use-callback-ref"
 
export function Component() {
  const handleClick = useCallbackRef((event: React.MouseEvent) => {
    console.log("Button clicked!", event)
  })
 
  return <button onClick={handleClick}>Click Me</button>
}

API Reference

Parameters

NameTypeDescriptionDefault ValueOptional
callbackT | undefinedThe callback function to memoize, where T is a function type with any arguments and return value. Can be undefined.undefinedYes

Return Values

NameTypeDescription
callbackRefT | undefinedA memoized version of the callback function that always uses the latest callback reference.