Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Await not working when pass async function as params LODASH

I created a custom function with params using callback to reuse, but await not working

const _debounceSearch = debounce(
    async (callback: (params: RequestParams) => any, value: string | undefined, language: string | undefined) => {
      const data = await callback({ q: value, lang: language });

      console.log('data on search', data);

      return data;
    },
    300,
  );

const dataCompanies = await _debounceSearch(apiSearchCompany, searchValue, languageParam);

        console.log('dataCompanies', dataCompanies);

        if (dataCompanies) {
          setCompanySearchTags(
            data.items.map((item: Company) => ({ value: item.id, label: item.name, checked: false })),
          );
        }

I only got undefined result although i pass await prefix.

Result

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I don’t think debounce function itself can be a promise. debounce(fn) is just a regular function, but you can make a Promise whenever you want.

Maybe checkout, Using lodash debounce to return a promise

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading