Skip to content

This is a custom hook for debouncing a callback (e.g. for click handlers) such that a callback will not be fired until some delay has passed since the last click. It can can be used on multiple instances ex-when we want to prevent excessive API Calls attached to click event.

Notifications You must be signed in to change notification settings

Sanidhya22/useDebouce.ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Debounce Click Event Hook for React

Introduction

Debouncing is a technique used to improve the performance of an application by limiting the rate at which a function is executed. In the context of click events, debouncing can help to reduce the number of API calls made in response to rapid or repetitive user interactions, such as multiple clicks on a button.

How it Works

This hook makes it easy to debounce click events in your React components, by wrapping your event handler in a debounced function and returning it for use with the onClick prop. The hook uses the setTimeout API to wait for a specified time period after the last click before executing the handler, and it clears the timeout whenever a new click occurs, resetting the countdown.

About

This is a custom hook for debouncing a callback (e.g. for click handlers) such that a callback will not be fired until some delay has passed since the last click. It can can be used on multiple instances ex-when we want to prevent excessive API Calls attached to click event.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published