UNPKG

jobiqo-cl

Version:

[![CircleCI](https://circleci.com/gh/jobiqo/jobiqo-cl.svg?style=svg&circle-token=5a24efa5b8bbc4879276123e77d0d3f35ca7144c)](https://circleci.com/gh/jobiqo/jobiqo-cl)

18 lines (15 loc) 679 B
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 };