react-fuzzysort
TypeScript icon, indicating that this package has built-in type declarations

1.0.1Β β€’Β PublicΒ β€’Β Published

React Fuzzysort

πŸ”Ž The Fuzzysort library implemented as a handy React component

Installation

npm install react-fuzzysort
# or
yarn add react-fuzzysort

Basic Usage

import { Search } from 'react-fuzzysort';

function Catalogue() {
  const input = useRef<HTMLInputElement>(null);

  return (
    <Wrapper>
      <SearchBar ref={input} />
      <Search
        input={input}
        fallback={<FallbackText>No results!</FallbackText>}
        list={[
          { query: 'carrot', node: <Item>πŸ₯• Carrot</Item> },
          { query: 'banana', node: <Item>🍌 Banana</Item> },
          { query: 'ketchup', node: <Item>πŸ… Ketchup</Item> },
          // and so on...
        ]}
      />
    </Wrapper>
  );
}

Work Smarter By Mapping!

const list = ['πŸ₯• Carrot', '🍌 Banana', 'πŸ… Ketchup'];

return (
  <Search
    list={list.map((listItem) => ({
      query: listItem,
      node: <Item>{listItem}</Item>,
    }))}
  />
);

Documentation

Info: documentation is temporarily available in the README while my website undergoes construction

Configuration Options

These are passed down as props to the Search component.

list

  • A list of items to be searched from
  • This is an array of objects (SearchItem[])
  • Search items includes:
    • query: the string that is compared against the input value
    • node: the thing that is rendered

input

  • A React ref to the search input

fallback

  • The fallback that is rendered when there are no results

debounce

  • A debounce time avoids excessive rerenders
  • By default, it is 0 which has proven to be fine for a couple thousand items

onFirstItemChange

  • Fires when the first item in the list changes
  • Does not fire on mount

onNoResults

  • Fires when there are no results
  • Does not fire when there are no results multiple times in a row

keyOptions

Changelogs

v1.0.1

  • Fixed several issues with package.json

v1.0.0

  • Added React Fuzzysort

Readme

Keywords

none

Package Sidebar

Install

npm i react-fuzzysort

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

8.02 kB

Total Files

6

Last publish

Collaborators

  • tresabhi