SniberbS
Reactifluxβ€’4y agoβ€’
6 replies
Sniberb

πŸŽƒ 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);
  };
Was this page helpful?