Loading...
Please waitLoading...
Please waitDelay function execution with useDebounceCallback, providing options for canceling, flushing, and checking if a call is pending.
pnpm dlx uselab@latest add use-debounce-callback
import * as React from "react"
import { useDebounceCallback } from "@/hooks/use-debounce-callback"
export function Component() {
const [value, setValue] = React.useState("")
const debounced = useDebounceCallback(setValue, 500)
return (
<div>
<p>Debounced value: {value}</p>
<input
type="text"
defaultValue={value}
onChange={(event) => debounced(event.target.value)}
/>
</div>
)
}| Name | Type | Description | Default Value | Optional |
|---|---|---|---|---|
Function | () => void | The cleanup function to be executed on unmount. | - | No |
| Type | Description |
|---|---|
Function | The debounced function that can be called to execute the original function after the delay. |