I have a list that I want to filter and return the list to display on the screen. This list is coming from an api which is returning all the data at once. My function for debounce looks like this
const debouncedFn = React.useCallback((fn: Function, delay: number) => {
let timer: any = null;
return (...args: any) => {
clearTimeout(timer);
timer = setTimeout(() => fn(...args), delay);
};}, []);
I am calling this inside useMemo hook like this
let filteredItems = React.useMemo(() => {
const p = debouncedFn(filterList, 400);
console.log("p", p());
return p();
}, [debouncedFn]);
And the filterlist function is like this
const filterList = () => {
return userList.filter((x: any) => x.advertiser_name.includes(filterValue));
};
I am expecting the filtered results inside filteredItems but it is coming undefined.