How to use the use-debounce/lib/callback function in use-debounce

To help you get started, we’ve selected a few use-debounce examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / ui / components / sidebar / org-switcher / with-data.tsx View on Github external
setCurrentOrganizationId,
    organizationsAvailableToUser: organizations,
  } = useCurrentOrganization();

  const [searchResults, setResults] = useState(organizations);

  const selectOrganization = (id) => () => {
    setCurrentOrganizationId(id);
    toggle();
  };

  // TODO: clean this up once
  //       https://github.com/orbitjs/orbit/pull/525
  //       is merged, where we'll be able to retrieve the query result
  //       without local filtering. (so we can skip the cache query step)
  const performSearch = useDebouncedCallback(
    async () => {
      const filters = [{ attribute: 'name', value: `like:${searchTerm}` }];

      if (!isSuperAdmin) {
        filters.push({ attribute: 'scope-to-current-user', value: 'isnull:' });
      }

      await dataStore.query((q) => q.findRecords(ORGANIZATION).filter(filters), defaultOptions());

      const records = await dataStore.cache.query((q) => q.findRecords(ORGANIZATION));
      // TODO: MAY need to do a local filter on organizations that the current user owns
      const filtered = records.filter((record) => {
        const { name } = attributesFor(record);
        if (!name) {
          return false;
        }

use-debounce

Debounce hook for react

MIT
Latest version published 2 months ago

Package Health Score

85 / 100
Full package analysis