Git Product home page Git Product logo

react-fuzzysort's Introduction

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

react-fuzzysort's People

Contributors

dependabot[bot] avatar tresabhi avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.