Sniberb
Sniberbβ€’2y ago

πŸŽƒ 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);
};
3 Replies
liil'boo
liil'booβ€’2y 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
Sniberb
Sniberbβ€’2y ago
theres nothing null or undefined it works if its not async but I also need it for async functions thanks btw @Liil' Boo
reactibot
reactibotβ€’2y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1034773473689604127