Debouncer that support react synthetic events.
function debounce(func, wait, immediate) {
var timeout;
return (...args) => {
const context = this;
args[0].persist();
const later = () => {
timeout = null;
if (!immediate) func.apply(context, args);
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};