πŸŽƒ 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);
};
LB
Liil' Booβ€’540d ago
Hello, @β›„Snowberbβ›„ I'm thinking, maybe, asynchrony issue ? Are you certain of your debounce function's behavior when given an async function ? Is it normal that 'accoutCodeExists' does not return anything ?* Is it borrowed code or your code ? Awaiting your answer, I think I have the solution
S
Sniberbβ€’540d ago
theres nothing null or undefined it works if its not async but I also need it for async functions thanks btw @Liil' Boo
UU
Unknown Userβ€’540d ago