0.1.1 • Published 8 months ago
@1ohooks/use-debounce v0.1.1
@1ohooks/use-debounce
The @1ohooks/use-debounce
package provides a custom React hook for implementing debouncing in your applications.
Installation
You can install @1ohooks/use-debounce
using npm or yarn:
npm install @1ohooks/use-debounce
# or
yarn add @1ohooks/use-debounce
Documentation
useDebounce
The useDebounce
hook allows you to debounce a function, delaying its execution until after a specified delay period.
import { useDebounce } from '@1ohooks/use-debounce';
// Usage example
function MyComponent() {
const [debouncedFunction, cancelDebounce] = useDebounce(() => {
// Your debounced function logic
}, 300);
// Call debouncedFunction to execute the debounced logic
return (
// Your component JSX
);
}
Parameters
callback
(Function): The function to be debounced.delay
(number): The delay time in milliseconds before executing the debounced function.options
(Object, optional): Additional options for customizing the debounce behavior.immediate
(boolean, optional): Iftrue
, the callback will be executed immediately on the leading edge. Default isfalse
.maxWait
(number, optional): The maximum time in milliseconds to wait between invocations. Default isundefined
.
Return Values
debouncedFunction
(Function): The debounced function that you should call to trigger the debounced logic.cancelDebounce
(Function): A function to cancel the debounce and prevent the debounced function from being executed.
Requirements
- React 16 or higher.
Usage
You can use the useDebounce
hook in your React components to debounce functions and improve performance. It is particularly useful for handling user input, search requests, and more.
For advanced usage and customization options, refer to the hook documentation.
Thank you for using @1ohooks/use-debounce
to implement debouncing in your React applications. We hope you find it valuable!