I'm not understanding the debounce return, I understand about the rest and spread operator but my question is, when I console.log(...args) it's related to input event but how return receives it ?
const fetchData = async (searchTerm) => {
const response = await axios.get('http://www.omdbapi.com/', {
params: {
apikey: '',
s: searchTerm,
},
});
console.log(response.data);
};
const input = document.querySelector('input');
const debounce = (func) => {
let timeoutId;
return (...args) => {
if (timeoutId) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(() => {
func.apply(null, args);
}, 2000);
};
};
const onInput = debounce((event) => {
fetchData(event.target.value);
});
input.addEventListener('input', onInput);