1.2.0-rc.19 • Published 7 months ago

@digigov/text-search v1.2.0-rc.19

Weekly downloads
-
License
BSD-2-Clause
Repository
-
Last release
7 months ago

@digigov/text-search

@digigov/text-search is a library that provides text search functionality in the form of a React hook. It allows searching through a list of objects by creating an index of the objects' properties. It uses flexsearch under the hood.

The objects in the list can have any structure, but an identifier property must be provided. The hook will use the id property (if present) or it will create an id property for each object, using the index of the object in the list. Alternatively, you may specify which property to use as an identifier by passing it in the idKey of the hook's options. Obviously, the identifier property must be unique for each object.

Installation

npm install @digigov/text-search

or

yarn add @digigov/text-search

Usage

Here is a basic example of how to use the hook:

import React from 'react';
import useSearch from '@digigov/text-search';

const documents = [
  { name: 'John', address: '123 Main St' },
  { name: 'Jane', address: '456 Main St' },
  { name: 'Jack', address: '789 Main St' },
  { name: 'Jill', address: '101 Main St' },
];

const MyComponent = () => {
  const [searchTerm, setSearchTerm] = React.useState('');
  const { data, loading, search, reset } = useSearch(documents, searchTerm);

  const handleReset = () => {
    setSearchTerm('');
    reset();
  };

  return (
    <div>
      <input
        type="text"
        value={searchTerm}
        onChange={(e) => setSearchTerm(e.target.value)}
        placeholder="Enter search term"
      />
      <button onClick={search}>Search</button>
      <button onClick={handleReset}>Reset</button>

      {loading && <p>Loading...</p>}

      <ul>
        {data.map((item) => (
          <li key={item.name}>
            <p>{item.name}</p>
            <p>{item.address}</p>
          </li>
        ))}
      </ul>
    </div>
  );
};

export default MyComponent;
1.2.0-60d81ed8

7 months ago

1.2.0-b4cd6916

8 months ago

1.2.0-rc.19

8 months ago

1.2.0-36b707c1

8 months ago

1.2.0-113e6661

9 months ago

1.2.0-6e3977bc

8 months ago

1.2.0-daaf7bdf

8 months ago

1.1.3-0edebf87

1 year ago

1.2.0-85c27c19

10 months ago

1.2.0-d57821ba

10 months ago

1.2.0-6c42d5eb

10 months ago

1.2.0-2445d5cb

10 months ago

1.2.0-rc.18

9 months ago

1.2.0-f0a886ce

10 months ago

1.2.0-rc.17

11 months ago

1.1.3-rc.14

11 months ago

1.1.3-rc.15

11 months ago

1.1.3-rc.16

11 months ago

1.1.3-rc.10

1 year ago

1.1.3-rc.11

12 months ago

1.1.3-rc.12

12 months ago

1.1.3-rc.13

11 months ago

1.1.2-fd2cea11

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.0-2a507fd6

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.0.0-rc.5

1 year ago

1.0.0-rc.6

1 year ago

1.0.0-51c931ab

2 years ago

1.0.0-23c81d9f

2 years ago

0.1.0-47312a12

2 years ago

0.1.0-b0737a96

2 years ago

0.1.0-rc.4

2 years ago

0.1.0-8b33e4c8

2 years ago

0.1.0-b4257f67

2 years ago

0.1.0-a131264d

2 years ago