
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
@custom-react-hooks/use-debounce
Advanced tools
The `useDebounce` hook is used to delay the execution of a function until a specified amount of time has passed since it was last invoked. This is useful for handling rapid user input scenarios, such as search input fields or window resizing.
The useDebounce hook is used to delay the execution of a function until a specified amount of time has passed since it was last invoked. This is useful for handling rapid user input scenarios, such as search input fields or window resizing.
Choose and install individual hooks that suit your project needs, or install the entire collection for a full suite of utilities.
npm install @custom-react-hooks/use-debounce
or
yarn add @custom-react-hooks/use-debounce
npm install @custom-react-hooks/all
or
yarn add @custom-react-hooks/all
Here's an example of using useDebounce in a search input component:
import React, { useState } from 'react';
import useDebounce from 'custom-react-hooks/useDebounce';
const DebounceTestComponent: React.FC = () => {
const [inputValue, setInputValue] = useState('');
const debouncedLog = useDebounce((val: string) => {
console.log(`Debounced value: ${val}`);
}, 1000)[0];
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setInputValue(e.target.value);
debouncedLog(e.target.value);
};
return (
<div>
<input
type="text"
value={inputValue}
onChange={handleChange}
/>
</div>
);
};
export default DebounceTestComponent;
In this component, the search function is debounced, which means it will only execute 500 milliseconds after the user stops typing.
callback (Function): The function to debounce.delay (number): The number of milliseconds to delay.options (object, optional): Configuration options for the debounce behavior. Options include:
maxWait (number): The maximum time the function can be delayed before it's executed, regardless of subsequent calls.leading (boolean): If true, the function is executed on the leading edge of the timeout.trailing (boolean): If true, the function is executed on the trailing edge of the timeout.[debouncedFunction, cancelDebounce]:
debouncedFunction (Function): The debounced version of the provided function.cancelDebounce (Function): A function that can be called to cancel the debounced action.useDebounce hook is useful for optimizing performance in scenarios where you want to limit the frequency of function execution.Your contributions are welcome! Feel free to submit issues or pull requests to improve the useDebounce hook.
FAQs
The `useDebounce` hook is used to delay the execution of a function until a specified amount of time has passed since it was last invoked. This is useful for handling rapid user input scenarios, such as search input fields or window resizing.
The npm package @custom-react-hooks/use-debounce receives a total of 667 weekly downloads. As such, @custom-react-hooks/use-debounce popularity was classified as not popular.
We found that @custom-react-hooks/use-debounce demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.