R
Reactiflux

πŸŽƒ Spookyberb πŸŽƒ – 10-20 Oct 26

πŸŽƒ Spookyberb πŸŽƒ – 10-20 Oct 26

Sβ›„Snowberbβ›„10/26/2022
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);
};
LBLiil' Boo10/26/2022
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β›„Snowberbβ›„10/26/2022
theres nothing null or undefined it works if its not async but I also need it for async functions thanks btw @Liil' Boo
UUUnknown User10/26/2022
Message Not Public
Sign In & Join Server To View

Looking for more? Join the community!

R
Reactiflux

πŸŽƒ Spookyberb πŸŽƒ – 10-20 Oct 26

Join Server