I am trying to use the debounce
function to avoid multiple calls when I'm typing and searching something in a datatable. What I am doing now is in the input
onChange={(e) => {
const delayedQuery = useCallback(debounce(this.handleSearch(e.target.value), 500));
return delayedQuery
}}
where handeSearch
is
handleSearch(filter) {
service.getData(filter).subscribe((data) => {console.log(data)})
}
but I have this error TypeError: Expected a function
. The service is working but the debounce nope. It writes character by character at the same time I'm typing and that's not correct.