π Spookyberb π β 10-20 Oct 26
Why is my debounce function not calling the function?
useEffect(() => {
if (watchedAccountCode) {
debounce(accountCodeExists);
}
}, [watchedAccountCode]);
export const debounce = (callback, timeout = 300) => {
let timer;
return () => {
clearTimeout(timer);
timer = setTimeout(() => {
callback();
}, timeout);
};
};
const accountCodeExists = async () => {
const code = getValues('accountCode');
const searchedAccount = await getAllAccounts(UUID, { $filter: `accountCode=${code}` });
console.log('searchedAccount', searchedAccount);
};useEffect(() => {
if (watchedAccountCode) {
debounce(accountCodeExists);
}
}, [watchedAccountCode]);
export const debounce = (callback, timeout = 300) => {
let timer;
return () => {
clearTimeout(timer);
timer = setTimeout(() => {
callback();
}, timeout);
};
};
const accountCodeExists = async () => {
const code = getValues('accountCode');
const searchedAccount = await getAllAccounts(UUID, { $filter: `accountCode=${code}` });
console.log('searchedAccount', searchedAccount);
};