1.0.0 • Published 4 months ago

use-searchable-list v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

useSearchableList

This project is partially maintained feel free to request update/post issue on the github though!

A hook written for a personal project that I decided could be useful to I separated it out to its own package to deploy to npm for others to use, plus with it beeing open source anyone can contribute to improve it for the better of us all.

npm bundle size (version) GitHub

Options

NameTypeDescription
clearOnEmptybooleanShould the list be empty if there is no filter value
firstCharacterCheckbooleanShould the first character entered run a startsWith check
debouncebooleanShould the filter list use debounce
delaynumberThe delay of the debounce

Example Usage

Define the hook baseed on the filter property name & optionally set props

const [people, setPeople, filter] = useSearchableList<Person>('firstname', {
  debounce: true,
  delay: 300
});

Call the filter function and pass in a value to filter by

  const handleChange = (event: React.FormEvent<HTMLInputElement>) => {
    const value: string = event.currentTarget.value;
    filter(value);
  };

  return (
    <div className="App">
      <h1>People</h1>
      <input
        className="SearchBar"
        onChange={handleChange}
        type="text"
        name="example"
        placeholder="Search..."/>
        ....

Use the returned list to display whatever you want to do

<div className='PersonList'>
    {people.map((person: Person) => {
        return (
            <PersonProfile
                firstname={person.firstname}
                lastname={person.lastname}
                email={person.email}
            />
        );
    })}
</div>

example

1.0.0

4 months ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago