A personal implementation of debounce in JavaScript
In this example the alert happens only one time after 2000 milliseconds, regardless of the amount of user interactions until it stops. It can be used in events like onChange in ReactJS, for example.
import debounce from './debounce.js';
const handleSearch = debounce(typing => {
alert(typing);
}, 2000);
handleSearch('foo');
Reference: Throttle and Debounce patterns in JS