jobiqo-cl
Version:
[](https://circleci.com/gh/jobiqo/jobiqo-cl)
18 lines (15 loc) • 679 B
JavaScript
import { useMemo } from 'react';
import matchSorter from '../../node_modules/match-sorter/dist/match-sorter.esm.js';
import { useThrottle as lib_1 } from '../../node_modules/use-throttle/lib/index.js';
/**
* @file index.tsx
*
* @fileoverview Helper hook to match characters in a list of items.
* Taken a list and a word it will find elements
* of the list that match the word. Also can take a pattern for how to match the word to the items.
*/
const useMatch = (data, term, pattern) => {
const throttledTerm = lib_1(term, 100);
return useMemo(() => (term.trim() === '' ? [] : matchSorter(data, term, pattern)), [throttledTerm]);
};
export { useMatch };