debounce-example
v1.0.2
Published
Sample debounce function
Maintainers
Readme
Debounce example
Installation
npm i [email protected]
Usage
import debounce from 'debounce-example';
Parameters
debounce(fn, time)
| Parameter name | Value | required |
| ------------- | ------------- | ------------- |
| fn - function | Contains function to be executed | yes |
| time - Number | Indicates time to executed the function | yes |
About
The debounce function helps to manage time of execution your scripts. You can use this function to disabled multiple execution of some function. For example:
- When you use a form to sent some data, and you need to prevent multiple call to the endpoint registration.
import debounce from 'debounce-example';
// Some function
const myAwesomeRegistrationLogin = () => {
fetch('http://my.api/user/registration', {
method: 'POST',
data: {name, email}
}).then(() => someNotification('Success registration'));
};
document.getElementById('registration--button').on('click', () => {
debounce(myAwesomeRegistrationLogin, 5000);
});
