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
Name | Type | Description | Default Value | Optional |
---|---|---|---|---|
callback | T | undefined | The callback function to memoize, where T is a function type with any arguments and return value. Can be undefined . | undefined | Yes |
Return Values
Name | Type | Description |
---|---|---|
callbackRef | T | undefined | A memoized version of the callback function that always uses the latest callback reference. |