I was trying to implement debounce but it did not work as expected, I could not understand why, the debounced function was not returning anything. it was returning undefined
const debounce = (mainFunction, delay) => {
let timer;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => {
return mainFunction(...args);
}, delay);
};
};
function searchData() {
console.log("searchData executed");
return "hello";
}
const debouncedSearchData = debounce(searchData, 3000);
const testData = debouncedSearchData();
console.log(testData);